Skip to content

Save

Defined in: packages/save/src/Save.ts:262

Save instance — IO over typed Serializable values. Created with createSave({ adapter }) and registered in the engine via SavePlugin so components can resolve it through SaveServiceKey.

new Save(opts): Save

Defined in: packages/save/src/Save.ts:276

CreateSaveOptions

Save

readonly adapter: SaveAdapter

Defined in: packages/save/src/Save.ts:263

autoPersist<T>(id, thing, opts?): () => void

Defined in: packages/save/src/Save.ts:431

Subscribe to a reactive value and persist on every change, coalesced to a single in-flight write per id. Returns a stop function — call it to unsubscribe.

Writes are serialized: while a persist() is in flight, further changes mark the value dirty and trigger one more write after the current one resolves. The last-set state always wins, even on a slow async adapter, because each flush re-reads thing.serialize() rather than capturing the value at scheduling time. Multiple synchronous mutations collapse into one write because the dirty flag is consumed atomically.

setTimeout is intentionally not used here: Save runs alongside the page lifecycle, not the engine loop, and may be active before the engine starts or after it stops (e.g. settings menus on a paused game). Using engine-time processes here would tie persistence to a running scheduler.

T

string

Serializable<T> & Reactive

PersistOptions

() => void


deleteSlot(id, slot): Promise<void>

Defined in: packages/save/src/Save.ts:368

Delete a slot. No-op when the slot doesn’t exist.

string

string

Promise<void>


listSlots<M>(id, opts?): Promise<SlotInfo<M>[]>

Defined in: packages/save/src/Save.ts:350

List slots for a store id, optionally filtered by prefix.

M = unknown

string

string

Promise<SlotInfo<M>[]>


loadSlot<T>(id, slot, thing, opts?): Promise<void>

Defined in: packages/save/src/Save.ts:337

Load a slot. Throws SlotNotFoundError when missing.

T

string

string

Serializable<T>

RestoreOptions<T>

Promise<void>


persist<T>(id, thing, opts?): Promise<void>

Defined in: packages/save/src/Save.ts:281

Persist the value as an unslotted document.

T

string

Serializable<T>

PersistOptions

Promise<void>


restore<T>(id, thing, opts?): Promise<void>

Defined in: packages/save/src/Save.ts:295

Restore an unslotted document. No-op when the document doesn’t exist — the value keeps its current (default) state.

T

string

Serializable<T>

RestoreOptions<T>

Promise<void>


saveSlot<T, M>(id, slot, thing, opts?): Promise<void>

Defined in: packages/save/src/Save.ts:310

Save into a named slot. The slot manifest is updated with the timestamp and optional metadata.

T

M = unknown

string

string

Serializable<T>

SaveSlotOptions<M>

Promise<void>

Coding agents: fetch https://yage.dev/llms.txt first and prefer the Markdown references it links over these HTML pages. This page's Markdown counterpart is /llms/packages/save.md.