Created
March 14, 2019 21:27
-
-
Save venil7/9ba354d28f5a9d4f31229f331859a3d3 to your computer and use it in GitHub Desktop.
a quick implementation of redux-obesrvable middleware
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
import { Subject } from "rxjs"; | |
export const createMiddleware = () => { | |
const [action$, state$] = [new Subject(), new Subject()]; | |
const middleware = store => { | |
return dispatch => { | |
middleware.run = epic => epic(action$, state$).subscribe(store.dispatch); | |
return action => { | |
const result = dispatch(action); | |
action$.next(action); | |
state$.next(store.getState()); | |
return result; | |
}; | |
}; | |
}; | |
return middleware; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment