Created
December 18, 2020 09:05
-
-
Save hindmost/d39d7f3580c6ae2d4ac289b8163283b5 to your computer and use it in GitHub Desktop.
reduxed-chrome-storage article: buffered dispatch version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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