Interface Observable<T>
Piece of observable data holding value of type
T
with means to read the value and bind to its updates.
Namespace: TinkState
Assembly: Nadako.TinkState.dll
Syntax
public interface Observable<out T>
Type Parameters
Name | Description |
---|---|
T | Type of the value being managed by this observable. |
Properties
Value
Current value of this observable object.
Declaration
T Value { get; }
Property Value
Type | Description |
---|---|
T | Current value of this observable object. |
Remarks
Depending on implementation, accessing this property might cause computation, so it's advised to only access it once
and cache the value in a local variable if it is to be used multiple times.
Methods
Bind(Action<T>, IEqualityComparer<T>, Scheduler)
Subscribe to value changes and attach given
callback
to be invoked when the value is updated.
Declaration
IDisposable Bind(Action<T> callback, IEqualityComparer<T> comparer = null, Scheduler scheduler = null)
Parameters
Type | Name | Description |
---|---|---|
System.Action<T> | callback | A function to invoke with the updated value. |
System.Collections.Generic.IEqualityComparer<T> | comparer | Custom comparer that will be used to determine if the value has changed for this binding to be triggered. |
Scheduler | scheduler | Custom scheduler that will manage invoking the callback. |
Returns
Type | Description |
---|---|
System.IDisposable | Disposable reference to the binding object for later unbinding. |
Remarks
The callback
will be immediately invoked once when binding.
Normally the callback
is not invoked directly on value update. Instead bindings are batched
together and scheduled to run once per frame. It is however possible to control this by passing a custom scheduler
object.
Map<TOut>(Func<T, TOut>, IEqualityComparer<TOut>)
Create a new observable from this observable that maps the value using given
transform
function.
Declaration
Observable<TOut> Map<TOut>(Func<T, TOut> transform, IEqualityComparer<TOut> comparer = null)
Parameters
Type | Name | Description |
---|---|---|
System.Func<T, TOut> | transform | Function to transform values of this observable to values of a new one. |
System.Collections.Generic.IEqualityComparer<TOut> | comparer | Custom comparer for the new observable to determine if bindings and derived auto-observables should be triggered. |
Returns
Type | Description |
---|---|
Observable<TOut> | The new observable with values mapped from this one. |
Type Parameters
Name | Description |
---|---|
TOut | Type of the values of the resulting observable. |
Remarks
The same effect can be achieved with the Auto<T>(Func<T>, IEqualityComparer<T>) constructor, however this method is more efficient as it doesn't require managing multiple subscriptions internally.
NOTE: this also means that observable access are not tracked within transform
function.