Method Select
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
Select<T>(Func<TState, T>, Action<T, T>, IEqualityComparer<T>?, bool)
Subscribes to a selected slice with a (currentSlice, previousSlice) signature. The listener fires only when the selected slice changes under the given comparer.
public IDisposable Select<T>(Func<TState, T> selector, Action<T, T> observer, IEqualityComparer<T>? comparer = null, bool fireImmediately = false)
Parameters
selectorFunc<TState, T>Pure projection from the store snapshot. Must not be null.
observerAction<T, T>Invoked with
(currentSlice, previousSlice)on each change. Must not be null.comparerIEqualityComparer<T>Equality comparer that decides whether two consecutive slices are equal. Defaults to reference (Object.is) equality, the same default used by UseStore<TStore, TSel>(Store<TStore>, Func<TStore, TSel>, IEqualityComparer<TSel>?). Pass Sequence<T>() to compare sequence slices element-by-element instead.
fireImmediatelyboolWhen
true, fires the observer synchronously with(selector(Current), selector(Current))before returning. Default isfalse.
Returns
- IDisposable
Type Parameters
TSelected projection type.