createTransitionTracker
projects/core/utils/transition-tracker.ts
Description#
Creates a reactive transition tracker for any value source. Defaults to
AsyncStatus - the original specialisation - but tracks booleans, enums,
or object snapshots (pass options.equal) just the same.
Uses linkedSignal internally - when source() changes, previous holds
the prior value and current holds the new one. Both are memoized signals.
At mount, previous equals the source's current value (no phantom
idle -> X transition for a source that mounts mid-flight); pass
options.seed to seed previous explicitly instead. The mount value is
captured lazily at the tracker's first read - a source change before
anything observes the tracker folds into the mount value instead of
fabricating a transition nobody watched happen.
Signature#
createTransitionTracker(source, options?: TransitionTrackerOptions)Parameters#
Reactive function that reads the current AsyncStatus.
Optional TransitionTrackerOptions.
const tracker = createTransitionTracker(() => this.state().status());
effect(() => {
const { current, previous } = tracker;
if (current() === previous()) return; // no change - deduplicated by linkedSignal
if (current() === 'success') { ... }
});Returns#
ValueTransition