Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: persist extension #277

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: update README.md
  • Loading branch information
amorgunov committed May 26, 2023
commit 57fd7c7f8ef0aad4237a6c389cfa58b0991d40f8
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,26 @@ server.listen()

### persist

TODO:https://
To persist database state and hydrate on page reload you can use persist extention. By default this one save database snapshoot in `sessionStorage` every time when any action was fired (like create new entity, update or delete).

```ts
import { factory, persist, primaryKey } from '@mswjs/data'

const db = factory({
user: {
id: primaryKey(String),
firstName: String,
},
})

persist(db)
```

You can pass any key-value storage with `getItem` and `setItem` methods (like `localStorage`) by second argument:

```
persist(db, { storage: localStorage })
```

## Honorable mentions

Expand Down