Documentation / @zerotal/flow / index / shared
Function: shared()
shared(
channel): (value,context) =>void
Defined in: flow/src/decorators.ts:565
Binds a field to convergent, server-authoritative shared state on a broadcast channel.
Parameters
channel
The channel name, or a resolver over the component instance.
Returns
A field decorator that registers the shared-state binding.
(value, context) => void
Remarks
Mutating the field inside an action writes to a per-channel room store and broadcasts to the
channel, so every other subscriber's component re-reads and converges (last-write-wins). The
channel resolves per-instance (a static string, or (self) => string for dynamic rooms) — the
same shape as presence, so one "room" channel can carry both who's-here (@presence)
and shared state (@shared). Serialized and read-only client-side (like @locked): clients
render it but can only change it through @expose actions. Applies to a field only.
Example
class Whiteboard extends Component {
@shared((self) => `board.${self.boardId}`)
strokes: Stroke[] = [];
@locked boardId = "";
@expose addStroke(stroke: Stroke) {
this.strokes = [...this.strokes, stroke]; // broadcasts to every subscriber
}
}