Created
October 8, 2018 15:42
-
-
Save idoshamun/a77a1825a9be00663f4c24679d858db9 to your computer and use it in GitHub Desktop.
Optimistic Offline-First Apps With Vuex
This file contains 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
import Vue from 'vue'; | |
import Vuex from 'vuex'; | |
import cache from './plugins/cache'; | |
import sync from './plugins/sync'; | |
Vue.use(Vuex); | |
export default new Vuex.Store({ | |
state: { | |
initialized: false, | |
}, | |
mutations: { | |
loadFromCache(state, cached) { | |
if (cached) { | |
Object.keys(cached).forEach((key) => { | |
state[key] = Object.assign({}, state[key], cached[key]); | |
}); | |
} | |
state.initialized = true; | |
}, | |
}, | |
plugins: [cache, sync], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment