Table of Contents

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

listener Action<TState>

Callback for state-change notifications. Must not be null.

fireImmediately bool

When true, the listener is invoked synchronously with Current before returning. Default is false — 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

listener Action<TState, TState>

Callback receiving (currentState, previousState). Must not be null.

fireImmediately bool

When true, fires the listener synchronously with (Current, Current) before returning (both arguments equal — there is no previous state at subscribe time). Default is false.

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.