Skip to content

feat: add snapshot utility#90

Closed
marcosvega91 wants to merge 4 commits intomainfrom
pr/add_snapshot_utility
Closed

feat: add snapshot utility#90
marcosvega91 wants to merge 4 commits intomainfrom
pr/add_snapshot_utility

Conversation

@marcosvega91
Copy link
Member

This is a first implementation of the snapshot utility. This will be updated after the implementation of the storage.

close #86

@marcosvega91 marcosvega91 force-pushed the pr/add_snapshot_utility branch from 1a5e22a to d494108 Compare April 28, 2021 20:05
@kettanaito
Copy link
Member

Hey, Marco! Thanks for putting this down.

I wouldn't merge this for now, as the issue isn't pressing and I will introduce some pre-requisite logic that we could then reuse in the snapshot. I'm currently working on the Database class serialization that's needed for the client-side persistence (#49), and I think the same serialization can be used for the snapshot utility.

If you don't mind, let's put this on hold for the time being, and once the persistence lands, let's see what we can reuse.

@micha149
Copy link

A bit late but I would like to suggest a slightly change to the api

import { factory, snapshot } from '@mswjs/data'

const db = factory({...})

// ...
// Set up some initial data
// ...

// Take a snapshot of all the entities in the DB and store it in a variable.
const applySnapshotWithInitialData = snapshot(db)

// Restores the DB to the previously taken snapshot. 
applySnapshotWithInitialData(db)

I think this will make a little more clear where the snapshot is applied to. Additionally it would enable us to create multiple instances and apply the snapshot to those as long as they have the same signature. One may call it copy-and-paste.

@kettanaito kettanaito mentioned this pull request Sep 28, 2025
@kettanaito
Copy link
Member

Released: v1.0.0 🎉

This has been released in v1.0.0.

Get these changes by running the following command:

npm i @msw/data@latest

Predictable release automation by Release.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a "snapshot" utility

3 participants