Method Subscribe
- Namespace
- Velvet
- Assembly
- Velvet.Docs.dll
Subscribe(Action<TState>, bool)
Subscribes to state changes.
public IDisposable Subscribe(Action<TState> listener, bool fireImmediately = false)
Parameters
listenerAction<TState>Callback for state-change notifications. Must not be null.
fireImmediatelyboolWhen
true, the listener is invoked synchronously with Current before returning. Default isfalse— the listener fires only on subsequent state changes.
Returns
- IDisposable
Subscribe(Action<TState, TState>, bool)
Subscribes to state changes with a (current, previous) signature.
public IDisposable Subscribe(Action<TState, TState> listener, bool fireImmediately = false)
Parameters
listenerAction<TState, TState>Callback receiving
(currentState, previousState). Must not be null.fireImmediatelyboolWhen
true, fires the listener synchronously with(Current, Current)before returning (both arguments equal — there is no previous state at subscribe time). Default isfalse.
Returns
- IDisposable
Remarks
Argument order note: listener takes (current, previous). This is the
reverse of the props comparator on Memo<TProps>(Func<TProps, VNode>, TProps, Func<TProps, TProps, bool>, string?), which takes
(previous, next) — the two areas settled on opposite conventions, so check the parameter
names at the call site rather than assuming one order.