@ogygia/federation · API
@ogygia/federation/shared
The reference for SharedState, one page-wide value that islands from separate builds share.
This page is generated from the package’s own .d.ts files on every build, so the signatures, descriptions and examples below always match the source. Shared state explains how to use it.
Exports SharedState
import { … } from '@ogygia/federation/shared';SharedState
class
One page-wide value that islands from separate builds share. Every build's copy of the class
meets at one page store under the same name. Read and write .current; values must be plain
data (devalue-serializable). A server can seed the opening value with <script type="application/json" data-og-shared="<name>">, and plain scripts can join through globalThis.ogygia.shared(name).
SharedState.constructor
SharedState.current
The value — reactive wherever Svelte is watching, plain everywhere else.
SharedState.current
The value — reactive wherever Svelte is watching, plain everywhere else.
class SharedState<T extends object> {/*…*/}import { SharedState } from '@ogygia/federation/shared';
export const cart = new SharedState('cart', { items: [] as string[] });constructor(name: string, initial: T);get current(): T;set current(v: T);