Computed<T> class
Namespace: Arlecchino.Atoms · Assembly: Arlecchino.Core
A value derived from other atoms. It re-evaluates lazily and tracks whatever it read while doing so, including other computed values and branches taken only sometimes — reading other.Value inside the lambda is the subscription.
public sealed class Computed<T> : IReadableAtom<T>
Implements IReadableAtom<T>
Constructors
| Member | Summary |
|---|---|
Computed(Func<T>) | Creates a derived value. |
Properties
| Member | Summary |
|---|---|
Value | The derived value, recomputed on the first read after any dependency changed. |
Methods
| Member | Summary |
|---|---|
Subscribe(Action) | Calls back whenever the derived value goes stale. |
Constructors in detail
Computed(Func<T>)
public Computed(Func<T> compute);
Creates a derived value.
Parameters
| Name | Type | Description |
|---|---|---|
compute | Func<TResult><T> | How to work it out. Reads of other atoms inside become the dependencies, so it may read different ones on different runs. |
Properties in detail
Value
public T Value { get; }
The derived value, recomputed on the first read after any dependency changed.
Type T
Methods in detail
Subscribe(Action)
public IDisposable Subscribe(Action listener);
Calls back whenever the derived value goes stale.
Parameters
| Name | Type | Description |
|---|---|---|
listener | Action | What to run on change. |
Returns IDisposable — Dispose it to stop listening.