applyPatchMessage
@rotorsoft/act-root / act-sse/src / applyPatchMessage
Function: applyPatchMessage()
applyPatchMessage<
S>(msg,cached):ApplyResult<S>
Defined in: libs/act-sse/src/apply-patch.ts:35
Apply a version-keyed patch message to the client's cached state.
Version logic
- All patches older than cached → "stale" (client already ahead)
- Gap between cached version and first patch → "behind" (client missed versions, must resync)
- Contiguous from cached version → apply in order
Usage (React Query)
onData: (msg) => {
const cached = utils.getState.getData({ streamId });
const result = applyPatchMessage(msg, cached);
if (result.ok) {
utils.getState.setData({ streamId }, result.state);
} else if (result.reason === "behind") {
utils.getState.invalidate({ streamId }); // trigger full refetch
}
// "stale" → no-op, client already has newer state
}
Type Parameters
S
S extends BroadcastState
Parameters
msg
PatchMessage<S>
cached
S | null | undefined
Returns
ApplyResult<S>