static class · System.Reactive
Reactive
public static class Reactive
- Kind
- static class
- Namespace
- System.Reactive
- Assembly
- System.Core
- Access
- public, static, abstract
- Source file
Reactive.ant
Inheritance
- Base classes
-
AnyReactive
Methods
Runs body now, and again whenever a reactive value it read changes.
Batch(func body)
#
Runs body; the effects its changes trigger run once each when it is done.
Runs an effect now, or once at the end of the batch in progress.
Flush()
#
Fields
Private and internal members (3)
Computes a lazy effect now, also inside a batch: a read of a computed sees the current values, not what it kept before the batch changed something it depends on. One scheduled in the batch is done with (it does not go stale again when the batch ends).
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
Reactive as Antril, decompiled from its Larva HIR.
// System.Reactive.Reactive — System.Core (decompiled from Larva HIR)
import System;
into namespace System.Reactive
{
public static class Reactive
{
i32 depth;
List<Effect?> pending;
internal:
/// Computes a lazy effect now, also inside a batch: a read of a computed sees the current values, not what it
/// kept before the batch changed something it depends on. One scheduled in the batch is done with (it does
/// not go stale again when the batch ends).
Refresh(Effect tracker)
{
if (tracker.Pending)
{
tracker.Pending = false;
i32 at = tracker.PendingAt;
if (at < pending.Count && pending[at] == tracker)
pending[at] = null;
tracker.Trigger();
}
if (tracker.Stale)
tracker.Run();
}
public:
/// The effect running now (what a Source being read should track), or null.
Effect? Current;
/// Runs `body` now, and again whenever a reactive value it read changes.
Watch(func body) : Effect
{
Effect effect = new Effect(body);
effect.Run();
return effect;
}
/// Runs `body`; the effects its changes trigger run once each when it is done.
Batch(func body)
{
depth++;
try
{
body();
}
finally
{
depth--;
if (depth == 0)
Flush();
}
}
/// Runs an effect now, or once at the end of the batch in progress.
Schedule(Effect effect)
{
if (depth == 0)
{
effect.Trigger();
return;
}
if (!effect.Pending)
{
effect.Pending = true;
effect.PendingAt = pending.Count;
pending.Add(effect);
}
}
Flush()
{
List<Effect?> due = pending;
pending = new List<Effect?>();
loop (i32 i = 0..due.Count)
{
if (due[i] is Effect effect)
{
effect.Pending = false;
effect.Trigger();
}
}
}
}
}