Skip to content

Instantly share code, notes, and snippets.

@venil7
Created March 14, 2019 21:27
Show Gist options
  • Save venil7/9ba354d28f5a9d4f31229f331859a3d3 to your computer and use it in GitHub Desktop.
Save venil7/9ba354d28f5a9d4f31229f331859a3d3 to your computer and use it in GitHub Desktop.
a quick implementation of redux-obesrvable middleware
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