Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hindmost/d39d7f3580c6ae2d4ac289b8163283b5 to your computer and use it in GitHub Desktop.
Save hindmost/d39d7f3580c6ae2d4ac289b8163283b5 to your computer and use it in GitHub Desktop.
reduxed-chrome-storage article: buffered dispatch version
class ReduxedStorage {
...
dispatch(action) {
if (!this.buffStore) {
this.buffStore = this.createStore(this.reducer, this.state, this.enhancer);
this.lastState = this.buffStore.getState();
setTimeout(() => {
this.buffStore = null;
}, 100);
}
this.buffStore.subscribe(() => {
const state = this.buffStore.getState();
if (isEqual(state, this.lastState))
return;
this.storage.save(state);
this.lastState = state;
});
return this.buffStore.dispatch(action);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment