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.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Save(
opts):Save
Defined in: packages/save/src/Save.ts:276
Parameters
Section titled “Parameters”Returns
Section titled “Returns”Save
Properties
Section titled “Properties”adapter
Section titled “adapter”
readonlyadapter:SaveAdapter
Defined in: packages/save/src/Save.ts:263
Methods
Section titled “Methods”autoPersist()
Section titled “autoPersist()”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”string
Serializable<T> & Reactive
Returns
Section titled “Returns”() => void
deleteSlot()
Section titled “deleteSlot()”deleteSlot(
id,slot):Promise<void>
Defined in: packages/save/src/Save.ts:368
Delete a slot. No-op when the slot doesn’t exist.
Parameters
Section titled “Parameters”string
string
Returns
Section titled “Returns”Promise<void>
listSlots()
Section titled “listSlots()”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.
Type Parameters
Section titled “Type Parameters”M = unknown
Parameters
Section titled “Parameters”string
prefix?
Section titled “prefix?”string
Returns
Section titled “Returns”Promise<SlotInfo<M>[]>
loadSlot()
Section titled “loadSlot()”loadSlot<
T>(id,slot,thing,opts?):Promise<void>
Defined in: packages/save/src/Save.ts:337
Load a slot. Throws SlotNotFoundError when missing.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”string
string
Serializable<T>
Returns
Section titled “Returns”Promise<void>
persist()
Section titled “persist()”persist<
T>(id,thing,opts?):Promise<void>
Defined in: packages/save/src/Save.ts:281
Persist the value as an unslotted document.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”string
Serializable<T>
Returns
Section titled “Returns”Promise<void>
restore()
Section titled “restore()”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.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”string
Serializable<T>
Returns
Section titled “Returns”Promise<void>
saveSlot()
Section titled “saveSlot()”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.
Type Parameters
Section titled “Type Parameters”T
M = unknown
Parameters
Section titled “Parameters”string
string
Serializable<T>
Returns
Section titled “Returns”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.