Created
August 16, 2017 16:06
-
-
Save sanketsahu/458f509973ce7e8d2257b358fe54de29 to your computer and use it in GitHub Desktop.
Using Redux DevTools with mobx-state-tree
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 { 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