Recipe: persist and restore state
luastra/state · luastra/host · app.resolve · about 15 minutesSave a versioned counter snapshot, restore it asynchronously, and reject malformed stored data without losing current state.
You will increment a counter, save it, change it again, then load the saved value. Reload the preview and load again to verify host persistence.
State.encode/decode is synchronous and deterministic; Host storage is asynchronous, so every request is correlated in app.resolve.
A successful storage read only proves that bytes were returned. Decode the versioned snapshot and validate domain values before replacing current application state.