Overview
createGlobalStore(StoreClass) instantiates a named class once on the window registry (keyed by constructor). Call it in the App root. The same class returns the existing instance — shell stores survive SPA navigation.
getGlobalStore(StoreClass) looks up that instance from children. Throws if App never called createGlobalStore for the class.
SSR: serializeLiveGlobalStores() builds a class-name → field-envelope map; buildGlobalStoreStateScript emits the transfer <script>. On hydrate, snapshots apply and load() is skipped; otherwise load() runs when present.
vs pageStore / store()
|
API
|
Lifetime
|
Prefer when
|
|---|---|---|
createGlobalStore
| app / shell | Survives navigation; create in App, getGlobalStore in children. |
getPageStore
| page | Cleaned up when the creating component unmounts. |
store(obj)
| module object | Proxy bag without class/SSR envelopes. |
createGlobalStore + getGlobalStore
App creates the store; Display looks it up. Same instance, no props.
Optional load()
When no SSR snapshot is present, load() runs once on create (playground has no snapshot).