Observables
Description
The observable helpers in Tesserae provide lightweight state containers that can notify components when values change. They are useful for UI state, reactive rendering, and collections that need to trigger updates when their contents change.
This page covers the most commonly used observable types:
SettableObservable<T>for mutable single valuesConstantObservable<T>for immutable values that should still satisfy an observable contractObservableList<T>for observable ordered collectionsObservableDictionary<TKey, TValue>for observable keyed collections
Usage
Use SettableObservable<T> when your code owns a value and needs to update it over time. Use ConstantObservable<T> when a consumer expects an IObservable<T> but the value never changes. Use ObservableList<T> and ObservableDictionary<TKey, TValue> when you need collection mutations to trigger UI updates.
SettableObservable
SettableObservable<T> is the mutable observable for single values. It derives from ReadOnlyObservable<T>, exposes a writable Value property, and supports an Update(Action<T>) helper for mutating reference types while still raising change notifications.
Key members:
SettableObservable.For<T>(value, comparer)creates a typed observable with inference.Valuegets or sets the current value.Update(Action<T>)mutates the current value and forces a notification.Observe(...),ObserveFutureChanges(...), andStopObserving(...)come from the underlying observable implementation.
ConstantObservable
ConstantObservable<T> wraps a fixed value in an IObservable<T> implementation. It immediately invokes Observe(...) with the stored value but never emits future changes.
Key members:
Valuegets the current value.Observe(...)invokes the callback immediately.ObserveFutureChanges(...)is a no-op.StopObserving(...)is a no-op.
ObservableList
ObservableList<T> implements IList<T>, ICollection<T>, and IObservable<IReadOnlyList<T>>. It raises change events when items are added, removed, inserted, replaced, or cleared.
Key members:
Delaycontrols the debounce delay before notifications are emitted.Valuereturns the current list asIReadOnlyList<T>.Add(...),AddRange(...),Insert(...),Update(...),Remove(...),RemoveAt(...),RemoveAll(...), andClear()mutate the list.ReplaceAll(...)swaps the entire contents in one operation.
If T is itself observable, ObservableList<T> can hook nested observables and propagate future changes automatically.
ObservableDictionary<TKey, TValue>
ObservableDictionary<TKey, TValue> implements IDictionary<TKey, TValue> and IObservable<IReadOnlyDictionary<TKey, TValue>>. It is useful for lookup state, keyed caches, and dynamic maps that should refresh dependent UI.
Key members:
Valuereturns the current dictionary asIReadOnlyDictionary<TKey, TValue>.Add(...),AddRange(...), indexer assignment,Remove(...), andClear()mutate the dictionary.Observe(...),ObserveFutureChanges(...), andStopObserving(...)subscribe or unsubscribe listeners.
Like ObservableList<T>, it can optionally hook nested observable values and emit updates when those inner values change.