Skip to main content

applyPatchMessage

@rotorsoft/act-root


@rotorsoft/act-root / act-http/src/sse / applyPatchMessage

Function: applyPatchMessage()

applyPatchMessage<S>(msg, cached): ApplyResult<S>

Defined in: libs/act-http/src/sse/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>