Skip to content

Instantly share code, notes, and snippets.

@idoshamun
Last active June 17, 2019 14:18
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/980faa86bb93f30317442e7a44098db1 to your computer and use it in GitHub Desktop.
Save idoshamun/980faa86bb93f30317442e7a44098db1 to your computer and use it in GitHub Desktop.
Optimistic Offline-First Apps With Vuex
import { setState } from './storage';
const shouldSkipCache = (mutation) => {
// Your business logic here
};
const plugin = (store) => {
store.subscribe((mutation, state) => {
if (!shouldSkipCache(mutation)) {
setState(state).catch(err => console.warn('failed to cache state', err));
}
});
};
export default plugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment