Skip to content

Instantly share code, notes, and snippets.

@idoshamun
Last active June 17, 2019 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idoshamun/33b925982642858c5541983db987efbe to your computer and use it in GitHub Desktop.
Save idoshamun/33b925982642858c5541983db987efbe to your computer and use it in GitHub Desktop.
Optimistic Offline-First Apps With Vuex
import localForage from 'localforage';
const store = localForage.createInstance({
name: 'app',
});
const mapStateForCache = (state) => {
// Your business logic here
};
export const setState = (state) => {
const cachedState = mapStateForCache(state);
return store.setItem('state', cachedState);
};
export const getState = () => store.getItem('state');
export const deleteState = () => store.removeItem('state');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment