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: add snapshot utility #90

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

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

@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.

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