Created
June 8, 2017 16:22
-
-
Save asfktz/1551b293805fcf291a923bd18176ee91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let pouchMiddleware | |
let invalidate = true; | |
const MyWrapperMiddleware = store => next => action => { | |
const state = store.getState() | |
if (!state.isLoggedIn) | |
return next(action) | |
if (someConditionForChange) { | |
invalidate = true | |
/* clean up, kill listeners if needed */ | |
} | |
if (!invalidate) { | |
invalidate = false | |
pouchMiddleware = PouchMiddleware({ | |
path: state.currentPath, | |
db, | |
actions: { | |
remove: doc => { return { type: types.DELETE_TODO, id: doc._id } }, | |
insert: doc => { return { type: types.INSERT_TODO, todo: doc } }, | |
batchInsert: docs => { return { type: types.BATCH_INSERT_TODOS, todos: docs } } | |
update: doc => { return { type: types.UPDATE_TODO, todo: doc } }, | |
} | |
}) | |
} | |
return pouchMiddleware(store)(next)(action) | |
} | |
export default MyWrapperMiddleware; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment