Skip to content

Instantly share code, notes, and snippets.

@idoshamun
Created October 8, 2018 15:42
Show Gist options
  • Save idoshamun/a77a1825a9be00663f4c24679d858db9 to your computer and use it in GitHub Desktop.
Save idoshamun/a77a1825a9be00663f4c24679d858db9 to your computer and use it in GitHub Desktop.
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