/** * vapor-chamber - SSR by the stores' states * * The server reads every store's state on the request's bus into the page * (`storeStates`), and the client gives them to its stores (`seedStores`): a * store already on the bus takes its state through its own write, one created * later starts from it. Nothing replays: a reducer that mints an id or reads a * clock ends on the server's state in the browser too. It works above Vue's DOM * hydration: no DOM references, anchors or interop state. Route data stays the * router's. * * CONCURRENCY. The shared bus is a module global, one per Node process. A * server that renders requests concurrently creates a bus per request: it * provides it to that request's app, and each store is created on it * (`useCart(bus)`). Its stores, and so its states, are that request's alone * (tests/ssr-per-request-bus.test.ts, tests/ssr-store-states.test.ts). * * The HTTP client has the same rule: its cache and in-flight dedupe map live * in `createHttpClient()`'s closure, and while the cache key holds the * request's headers it has no cookie dimension, so **create it per request** too. A client created once at module scope and * shared across renders lets user A's authenticated GET answer user B's. * * @example Server entry, per request * import { createSSRApp } from 'vue'; * import { renderToString } from 'vue/server-renderer'; * import { createCommandBus } from 'vapor-chamber'; * import { storeStates, serializeForScript } from 'vapor-chamber/ssr'; * * export async function render(App) { * const bus = createCommandBus(); * const app = createSSRApp(App); * app.provide('bus', bus); // in a component: useCart(inject('bus')) * const html = await renderToString(app); * return { html, states: storeStates(bus) }; * } * // Embed: * // (never JSON.stringify here: it leaves `` in user text intact) * * @example Client entry * import { createVaporChamberApp, getCommandBus } from 'vapor-chamber/vapor'; * import { seedStores } from 'vapor-chamber/ssr'; * * seedStores(getCommandBus(), window.__VAPOR_STATES__); * createVaporChamberApp(App).mount('#app'); */ import type { BaseBus } from './command-bus'; import type { ChamberStore } from './store-base'; /** * JSON for a `` cannot close the element it is * embedded in. Use it wherever the stores' states - which carry user text - * go into the page. * * @example * `` */ export declare function serializeForScript(value: unknown): string; /** * storeStates - the state of every store the request wrote on a bus, by store * id: what a server render puts into the page. A store still on the state it * was created with is left out, so the client's own load stands (its persist, * or `state()`): the server declares only what it wrote. A seeded id whose * store was never created is left out too. * * @example * const states = storeStates(bus); // { cart: { items: [...] }, user: { ... } } */ export declare function storeStates(bus: BaseBus): Record; /** * liveStores - the stores in use on a bus, in the order they were created: a * new array each call, so disposing or creating a store while iterating is * safe. A disposed store, and a seeded id whose store was never created, are * left out. It reads the registry the bus keeps, so no dispatch or write pays * for it. tests/live-stores.test.ts. * * @example * for (const store of liveStores(bus)) store.$reset(); */ export declare function liveStores(bus: BaseBus): Array>; /** * seedStores - give a server render's states to the client's stores, by id. * Each state is a fact on the bus's stores' lane: a store already on the bus * writes it at once through its own write (a step of its ring, saved by its * persist: the server's state wins over a saved one). For an id with no store * yet a placeholder holds the state, and a server's later one (a push before * the store exists) replaces it; the store starts from it when it is created. * Only an object is a state, as for a store. Call it before the app mounts. * * @example * seedStores(getCommandBus(), window.__VAPOR_STATES__); */ export declare function seedStores(bus: BaseBus, states: Record): void; //# sourceMappingURL=ssr.d.ts.map