/** @internal A command as it crosses: what a tab needs to apply it, and its id. */ export type WireCommand = { action: string; target: unknown; payload: unknown; id: string; causationId: string | undefined; ts: number; }; /** @internal An undo as it crosses: the id of the command it reverses, and the state it reached, for a tab that does not hold that command. */ export type WireUndo = { id: string; state: S; }; /** @internal A state set outside the reducers as it crosses, with an id its own tab knows it by when the lead posts it on. */ export type WireState = { id: string; state: S; }; /** @internal What a store sends: a command it ran, an undo, or a state set outside its reducers. */ export type TabSend = (kind: 'cmd' | 'undone' | 'state', value: WireCommand | WireUndo | S) => void; /** @internal What the store gives its tabs. */ export type TabHost = { id: string; cell: { readonly value: S; }; /** Lands an own write `coalesce` still holds, so an answer carries it. */ land: () => void; /** Sets what each write calls: the send, or null while no other tab is there. */ open: (send: TabSend | null) => void; /** Runs another tab's command with no dispatch. `again`: one this tab already ran, so its history is not told. `under`: see TabHearer. */ apply: (cmd: WireCommand, again: boolean, under?: readonly string[]) => void; /** Undoes the command with this id, as another tab did, or takes its state when this tab does not hold it. */ undo: (undo: WireUndo, again: boolean) => void; /** Writes a state another tab sent. */ put: (state: S) => void; /** The store keeps a ring of steps (`undo` or `optimistic`), so a write can be undone and run again. */ ring: boolean; /** Tells this bus's histories: here, that the state moved, so they read their top again. */ hear: (kind: 'moved') => void; /** Resolves once the store's saved state is read: null when there was none to wait for. */ ready: Promise | null; }; /** The value of a store's `share`, made by `shareTabs`: null where there are no tabs. `ready`: the store's `$ready`. */ export type StoreShare = (host: TabHost) => { dispose: () => void; ready: Promise; } | null; /** * @internal Whether this realm has tabs to share with: a page or a worker * with `BroadcastChannel`. Node, Deno and Bun define BroadcastChannel too: on * a server, two requests' stores of one id would share a channel, and each * would write the other's state. The one reader for `shareTabs` and the outbox. * tests/store-share.test.ts. */ export declare function _hasTabs(): boolean; /** * shareTabs - propagate a store across the tabs of one origin, the value of * its `share` option: one `BroadcastChannel` and one Web Lock per store, both * named `vc:store:` unless `name` is given. The tab holding the lock runs * every tab's command and posts it on, and the others follow it. A tab that * opens asks for the state and takes the lead's answer. Outside a page or a * worker (a server), without `BroadcastChannel` or without Web Locks, nothing * opens: without the lock, tabs could end on two states, so development warns. * * @example * defineChamberStore('cart', { state, reducers, share: shareTabs() }); */ export declare function shareTabs(name?: string): StoreShare; /** @internal What a state half gives `_shareStates`: its id, its state and its `put`. */ export type ShareHost = { id: string; cell: { readonly value: S; }; /** Lands an own write `coalesce` still holds. */ land: () => void; /** Writes a state another tab sent: the owner merges it. */ put: (state: S) => void; }; /** @internal What a state half does with one opened state sharing. */ export type ShareHooks = { /** On the half's watcher: sends the state a write reached. */ send: (next: S) => void; dispose: () => void; }; /** @internal A state half's sharing by whole states, for a state whose `put` merges. */ export type StateShare = (host: ShareHost) => ShareHooks | null; /** * @internal A state half shared by whole states (the outbox's queue): each * received state goes to `put`, which merges it, each tab the authority for * its own records, so nothing is weighed and no tab's change is dropped. A * tab that opens asks, and a tab that has written answers it alone. A * received state is not sent back. tests/outbox-tabs.test.ts. */ export declare function _shareStates(name: string): StateShare; //# sourceMappingURL=store-share.d.ts.map