Skip to content

feat: batch persist saves and add key-value and IndexedDB storages - #54

Merged
MatthewPattell merged 1 commit into
prodfrom
staging
Sep 30, 2026
Merged

MatthewPattell merged 1 commit into
prodfrom
staging

Conversation

@MatthewPattell

Copy link
Copy Markdown
Contributor

Promotes the persistence changes from #53 (released as 4.6.0-beta.1) to latest.

  • persisted stores track only their persisted attributes, referenced stores are not traversed
  • saves are batched per options.persistDelay (default 100 ms, 0 keeps save-on-every-change) and flushed on page hide, before a store is destroyed, on destroy() and on manager.flushPersist()
  • every changed storage is written once per batch, stores are compared and serialized by JSON once
  • optional IStorage.saveChanges for incremental saves
  • new KeyValueStorage and IndexedDBStorage with migration from an existing storage

Existing storages keep their data format. See #53 for details and benchmark.

Persisted stores were serialized with a deep toJS of the whole store on every
change, including other stores referenced from plain fields, and every change
rewrote the whole storage value.

- track only persisted attributes, referenced stores are not traversed
- batch changes per `persistDelay` (default 100 ms, 0 keeps save-on-every-change,
  the server always saves immediately)
- flush queued changes on page hide, before a store is destroyed, on destroy()
  and on `manager.flushPersist()`
- write every changed storage once per batch, compare stores by JSON and
  serialize each store once
- add optional `IStorage.saveChanges` for incremental saves, built-in
  single-value storages assemble JSON from cached store JSON
- add KeyValueStorage (a key per store: AsyncStorage, MMKV, localStorage) and
  IndexedDBStorage, both with migration from an existing storage
- CookieStorage warns once when the value exceeds 4 KB
@sonarqubecloud

Copy link
Copy Markdown

@MatthewPattell
MatthewPattell merged commit 8836101 into prod Sep 30, 2026
11 of 12 checks passed
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 4.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant