Vixen
02b45cc4
csharp
public sealed class Computed<T>

A value derived from other signals, evaluated on demand and memoised.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Lazy in the strong sense: a computed nobody reads is never evaluated, however many times its dependencies change. That is what makes it safe to define one per bindable property of a component whose panel is collapsed.

The computation must be a pure function of what it reads. It is re-run when the graph needs it and not otherwise, so a side effect in one happens an unpredictable number of times — writing a signal from inside one throws for that reason.

Dependencies are discovered by running it, so a computation that reads different signals on different runs is fully supported, and the dependency set narrows as well as widens. A computed guarding an expensive read behind a cheap flag stops depending on the expensive one the moment the flag goes false.

Fields and properties (1)

  • public T Value

    The derived value, evaluating it if a dependency has moved since the last read.

Methods (2)

  • public Computed(Func<T> compute, IEqualityComparer<T>? comparer = null)

    Creates a computed value from .

  • public T Peek()

    The current value without recording a dependency.

Used by (9)

  • ComputedTestsVixen.Ui.Reactive.Tests
  • EffectTestsVixen.Ui.Reactive.Tests
  • GraphTestsVixen.Ui.Reactive.Tests
  • SignalTestsVixen.Ui.Reactive.Tests
  • CommandStackVixen.Editor.Core
  • EditorDocumentVixen.Editor.Core
  • EditorDocumentTestsVixen.Editor.Core.Tests
  • EditorProjectVixen.Editor.Core
  • SelectionTestsVixen.Editor.Core.Tests