Skip to content

Instantly share code, notes, and snippets.

@sanketsahu
Created August 16, 2017 16:06
Show Gist options
  • Save sanketsahu/458f509973ce7e8d2257b358fe54de29 to your computer and use it in GitHub Desktop.
Save sanketsahu/458f509973ce7e8d2257b358fe54de29 to your computer and use it in GitHub Desktop.
Using Redux DevTools with mobx-state-tree
import { createStore } from "redux";
import { onSnapshot } from "mobx-state-tree";
export default class ReduxDevTools {
static logger(state = {}, action: { state: any; type: string }) {
return action.state;
}
static init(state: any) {
const store: any = createStore(
ReduxDevTools.logger,
(window as any).__REDUX_DEVTOOLS_EXTENSION__ &&
(window as any).__REDUX_DEVTOOLS_EXTENSION__()
);
onSnapshot(state, snapshot => {
store.dispatch({ type: "LOG", state: snapshot });
});
}
}
// use-case: ReduxDevTools.init(state) where state is an instance of mobx-state-tree model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment