final class · System.Reactive

Computed<T>

public final class Computed<T>

A value computed from reactive ones, kept until one of them changes: what computed T P => e; makes.

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

Parámetros de tipo

NombreRestricciones
Tcualquier tipo

Herencia

Clases base
Any Computed<T>

Constructores

new(func : T compute)
#

Propiedades

T Value { get; }
#

read-only

The value (computed now when stale); reading it inside an effect makes the effect depend on it.

bool Stale { get; }
#

read-only

Whether the next read computes it again.

Métodos

Dispose()
#

Stops tracking: it keeps its last value and no Source invalidates it again.

Miembros privados e internos (5)

func : T compute
#

private

T value
#

private

Source source
#

private

Effect tracker
#

private

Refresh()
#

private

Miembros heredados (5)

Código fuente

Computed<T> en Antril, descompilado a partir de su Larva HIR.

System.Reactive.Computed.ant
// System.Reactive.Computed — System.Core (decompiled from Larva HIR)

into namespace System.Reactive
{
	/// A value computed from reactive ones, kept until one of them changes: what `computed T P => e;` makes.
	public final class Computed<T>
	{
		func : T compute;
		T value;
		Source source;
		Effect tracker;

		Refresh()
		{
			value = compute();
		}

		public:
			new(func : T compute)
			{
				source = new Source();
				this.compute = compute;
				tracker = new Effect(() => { Refresh(); });
				tracker.Lazy = true;
				tracker.Stale = true;
				tracker.Dependents = source;
			}

			/// Stops tracking: it keeps its last value and no Source invalidates it again.
			Dispose()
			{
				tracker.Dispose();
			}

			/// The value (computed now when stale); reading it inside an effect makes the effect depend on it.
			T Value
			{
				get
				{
					source.Track();
					if (tracker.Stale || tracker.Pending)
						Reactive.Refresh(tracker);
					return value;
				}
			}

			/// Whether the next read computes it again.
			bool Stale
			{
				get => tracker.Stale;
			}
	}
}
Esc