Show / Hide Table of Contents

Class Observable

Static class containing Observable constructor methods and references to global utilities.
Inheritance
System.Object
Observable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: TinkState
Assembly: Nadako.TinkState.dll
Syntax
public static class Observable

Fields

Scheduler

Default scheduler used for bindings.
Declaration
public static Scheduler Scheduler
Field Value
Type Description
Scheduler
Remarks
This should be set to an environment-specific implementation before doing any bindings.

Methods

Auto<T>(Func<T>, IEqualityComparer<T>)

Create an observable containing data computed using given compute function.

Any access to Observable.Value from within compute calls will be automatically tracked by this observable to recompute its value and trigger its bindings.

Declaration
public static Observable<T> Auto<T>(Func<T> compute, IEqualityComparer<T> comparer = null)
Parameters
Type Name Description
System.Func<T> compute Computation function that returns a new value for this observable.
System.Collections.Generic.IEqualityComparer<T> comparer

Custom comparer that will be used to determine if the value has changed.

Used for triggering bindings and propagating changes to further auto-observables.

Returns
Type Description
Observable<T> Auto-observable providing computed values.
Type Parameters
Name Description
T Type of the value being managed by this observable.

Auto<T>(Func<CancellationToken, AsyncComputeTask<T>>)

Create an observable containing data computed using given compute function, similarly to Auto<T>(Func<AsyncComputeTask<T>>) but with support for cancelling computations.
Declaration
public static Observable<AsyncComputeResult<T>> Auto<T>(Func<CancellationToken, AsyncComputeTask<T>> compute)
Parameters
Type Name Description
System.Func<System.Threading.CancellationToken, AsyncComputeTask<T>> compute Cancelable computation function that asynchronously returns a new value for this observable.
Returns
Type Description
Observable<AsyncComputeResult<T>> Auto-observable providing current results of value computation.
Type Parameters
Name Description
T Type of the value being managed by this observable.
Remarks
The compute function receives a System.Threading.CancellationToken instance that will be automatically canceled if the auto-observable triggers a new computation (e.g. if one of its dependencies changes and we need to calculate a new value).

Auto<T>(Func<AsyncComputeTask<T>>)

Create an observable containing data computed using given compute function.

The difference with the Auto<T>(Func<T>, IEqualityComparer<T>) constructor is that this one takes an async function that does the computation asynchronously and the actual observable value will be of type AsyncComputeResult<T> representing the current status of asynchronous computation.

Any access to Observable.Value from within compute calls will be automatically tracked by this observable to recompute its value and trigger its bindings.

Declaration
public static Observable<AsyncComputeResult<T>> Auto<T>(Func<AsyncComputeTask<T>> compute)
Parameters
Type Name Description
System.Func<AsyncComputeTask<T>> compute Computation function that asynchronously returns a new value for this observable.
Returns
Type Description
Observable<AsyncComputeResult<T>> Auto-observable providing current results of value computation.
Type Parameters
Name Description
T Type of the value being managed by this observable.

AutoRun(Action, Scheduler)

Invoke given action and track Observable access inside it, similarly to Auto<T>(Func<T>, IEqualityComparer<T>) When any of the the tracked values changes, the action is scheduled for invocation again, in the same way as Bind(Action<T>, IEqualityComparer<T>, Scheduler) callbacks are.
Declaration
public static IDisposable AutoRun(Action action, Scheduler scheduler = null)
Parameters
Type Name Description
System.Action action Action to be invoked immediately as well as when any of the tracked value changes.
Scheduler scheduler Custom scheduler that will manage invoking the action.
Returns
Type Description
System.IDisposable Disposable reference to the binding for cancelling further re-invocations.

Const<T>(T)

Create a lightweight constant observable holding a value that never changes.
Declaration
public static Observable<T> Const<T>(T value)
Parameters
Type Name Description
T value Value for the observable to hold.
Returns
Type Description
Observable<T> Constant observable object holding given value.
Type Parameters
Name Description
T Type of the value being hold by this observable.

Dictionary<TKey, TValue>()

Create an empty observable dictionary.
Declaration
public static ObservableDictionary<TKey, TValue> Dictionary<TKey, TValue>()
Returns
Type Description
ObservableDictionary<TKey, TValue> New observable dictionary instance.
Type Parameters
Name Description
TKey The type of keys in the dictionary.
TValue The type of values in the dictionary.

List<T>()

Create an empty observable list.
Declaration
public static ObservableList<T> List<T>()
Returns
Type Description
ObservableList<T> New observable list instance.
Type Parameters
Name Description
T The type of elements in the list.

List<T>(IEnumerable<T>)

Create an observable list initialized with items from given initial collection.
Declaration
public static ObservableList<T> List<T>(IEnumerable<T> initial)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> initial
Returns
Type Description
ObservableList<T> New observable list instance.
Type Parameters
Name Description
T The type of elements in the list.

State<T>(T, IEqualityComparer<T>)

Create a mutable observable containing given initialValue.
Declaration
public static State<T> State<T>(T initialValue, IEqualityComparer<T> comparer = null)
Parameters
Type Name Description
T initialValue Initial value for this State to hold.
System.Collections.Generic.IEqualityComparer<T> comparer

Custom comparer that will be used to determine if the value has changed.

Used for triggering bindings and propagating changes to auto-observables.

Returns
Type Description
State<T>
Type Parameters
Name Description
T
In This Article
Back to top Generated by DocFX