API reference > @kontsedal/olas-realtime > createRealtimePatcher
createRealtimePatcher() function โ
Subscribe to channel for the lifetime of the surrounding controller and dispatch each event to the matching handler by event.type. Wrapper around the recurring SPEC ยง16.5 "realtime โ cache patches" pattern.
channel is a name or a signal of one. With a signal, a new name unsubscribes from the old channel and subscribes to the new one, so a per-route room is computed(() => 'room:' + params.value.roomId).
Handlers run inside untracked(...) so accidental signal reads (e.g.query.setData((prev) => prev.value)) don't add deps to the enclosing effect, which would otherwise re-subscribe whenever those signals change.
A '*' wildcard handler is invoked for every event, regardless of whether a specific handler matched. Specific handlers run first; the wildcard sees the same event afterwards (in the same untracked scope).
Signature:
export declare function createRealtimePatcher<TEvent extends {
type: string;
}>(ctx: Ctx<RealtimeDeps>, channel: string | ReadSignal<string>, handlers: PatcherHandlers<TEvent>): void;Parameters โ
Parameter | Type | Description |
|---|---|---|
ctx | ||
channel | string | ReadSignal<string> | |
handlers | PatcherHandlers<TEvent> |
Returns:
void