Skip to content

Instantly share code, notes, and snippets.

@idoshamun
Created Oct 8, 2018
Embed
What would you like to do?
Optimistic Offline-First Apps With Vuex
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