Last active
February 28, 2018 18:38
-
-
Save jgwhite/99545fec295804b1f11109e2a039d0ac to your computer and use it in GitHub Desktop.
Persisting Mirage’s DB in development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mirage/scenarios/default.js | |
export default function(server) { | |
function store() { | |
let data = server.db.dump(); | |
let json = JSON.stringify(data); | |
localStorage.mirage = json; | |
} | |
function load() { | |
let json = localStorage.mirage || '{}'; | |
let data = JSON.parse(json); | |
server.db.loadData(data); | |
} | |
load(); | |
server.pretender.handledRequest = store; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment