Interface SignalIntegration<T = | SignalNode | MemoNode> sincev5.10.0
interface SignalIntegration<T =
| SignalNode
| MemoNode> {
consumeSignal?: (signal: T) => void;
createMemo?: unknown;
createSignal?: (obj: object, key: string | symbol) => T;
isTracking?: () => boolean;
notifySignal?: (signal: T) => void;
waitFor?: <K>(promise: Promise<K>) => Promise<K>;
willSyncFlushWatchers?: () => boolean;
}Defined in: install.ts:76
Hooks that add another signals implementation, or a framework integration built on @warp-drive/alien-signals/primitives, to the graph that @warp-drive/alien-signals/install configures. Pass a function that builds them to registerSignalIntegration, or to registerSignals from @warp-drive/core/configure.
Every hook is optional, and an integration takes one of two shapes:
- It brings its own signals, such as Ember's tags.
createSignalcreates one alongside each graph signal, andconsumeSignalandnotifySignalreceive it whenever the graph signal is consumed or notified. Each memo the integration reads also gets one of its signals, created for the memo's key the first time it is read while the integration is tracking. Reading the memo consumes that signal, whether the memo runs or returns its cached result, and the graph notifies it as soon as anything the memo depends on changes. To the integration, a memo is just one more signal. - It observes the graph, as
@warp-drive/reactdoes. WithoutcreateSignal,consumeSignalreceives the graph's own nodes: each SignalNode when it is consumed, and each MemoNode just before it is read, whether it runs or returns its cached result.notifySignalreceives each SignalNode when it is notified.
Either kind may also use willSyncFlushWatchers and waitFor.
Memos always come from the graph, so a createMemo hook is ignored. This means the SignalHooks built for setupSignals can be registered as they are.
Type Parameters
T
T = | SignalNode | MemoNode
Properties
consumeSignal?
optional consumeSignal?: (signal: T) => void;Defined in: install.ts:88
Called when a signal is consumed. For an integration with its own signals, it is also called with the integration's signal for a memo each time that memo is read. For an integration that observes the graph, it is also called with each memo just before the memo is read.
Parameters
signal
T
Returns
void
createMemo?
optional createMemo?: unknown;Defined in: install.ts:114
Ignored: memos always come from the graph.
createSignal?
optional createSignal?: (obj: object, key: string | symbol) => T;Defined in: install.ts:82
Creates this integration's own signal for key on obj, paired with the graph signal created for the same key. Omit it to receive the graph's own nodes in consumeSignal and notifySignal instead.
Parameters
obj
object
key
string | symbol
Returns
T
isTracking?
optional isTracking?: () => boolean;Defined in: install.ts:100
For an integration with its own signals: whether a signal consumed now would be tracked. When this returns false, reading a memo neither consumes the integration's signal for it nor subscribes that signal to the memo's changes. Omit it to treat every read as tracked.
Returns
boolean
notifySignal?
optional notifySignal?: (signal: T) => void;Defined in: install.ts:94
Called when a signal is notified, after the graph has been notified. For an integration with its own signals, it is also called with the integration's signal for a memo once something the memo depends on changes.
Parameters
signal
T
Returns
void
waitFor?
optional waitFor?: <K>(promise: Promise<K>) => Promise<K>;Defined in: install.ts:110
See SignalHooks.waitFor. The graph passes each promise through every integration's waitFor, in the order they were registered.
Type Parameters
K
K
Parameters
promise
Promise<K>
Returns
Promise<K>
willSyncFlushWatchers?
optional willSyncFlushWatchers?: () => boolean;Defined in: install.ts:105
See SignalHooks.willSyncFlushWatchers. The graph's willSyncFlushWatchers returns true if any integration's does.
Returns
boolean