@statesync/core / InvalidationSubscriber
Interface: InvalidationSubscriber
Defined in: types.ts:125
A transport-agnostic contract for subscribing to invalidation events.
Implementations connect to a real-time channel (WebSocket, SSE, polling, etc.) and forward incoming InvalidationEvents to the provided handler.
Example
ts
const subscriber: InvalidationSubscriber = {
async subscribe(handler) {
const ws = new WebSocket('wss://example.com/sync');
ws.onmessage = (msg) => handler(JSON.parse(msg.data));
return () => ws.close();
},
};Methods
subscribe()
ts
subscribe(handler): Promise<Unsubscribe>;Defined in: types.ts:132
Registers a handler that will be called for each incoming invalidation event.
Parameters
| Parameter | Type | Description |
|---|---|---|
handler | (e) => void | Callback invoked with each InvalidationEvent. |
Returns
Promise<Unsubscribe>
A promise that resolves to an Unsubscribe teardown function.
