static class · System.Reactive

Reactive

public static class Reactive
Tipo
static class
Espacio de nombres
System.Reactive
Ensamblado
System.Core
Acceso
public, static, abstract
Archivo fuente
Reactive.ant

Herencia

Clases base
Any Reactive

Métodos

Watch(func body) : Effect
#

static

Runs body now, and again whenever a reactive value it read changes.

Batch(func body)
#

static

Runs body; the effects its changes trigger run once each when it is done.

Schedule(Effect effect)
#

static

Runs an effect now, or once at the end of the batch in progress.

Flush()
#

static

Campos

Effect? Current
#

static

The effect running now (what a Source being read should track), or null.

Miembros privados e internos (3)

i32 depth
#

private static

List<Effect?> pending
#

private static

Refresh(Effect tracker)
#

internal static

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).

Miembros heredados (5)

Código fuente

Reactive en Antril, descompilado a partir de su Larva HIR.

System.Reactive.Reactive.ant
// 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();
					}
				}
			}
	}
}
Esc