Last active
October 28, 2016 21:07
-
-
Save milankinen/49eb5140c3f341b302ffcb66cc582351 to your computer and use it in GitHub Desktop.
Redux devtools integration with @culli/store
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 {O, extend} from "@culli/base" // you can replace this with your own streaming library if you want | |
import Memory from "./memory" | |
function ReduxDevtools(initial) { | |
const devtools = window.__REDUX_DEVTOOLS_EXTENSION__ | |
if (!devtools) { | |
return Memory(initial) | |
} | |
function ReduxDevtoolsStorage(actions) { | |
return O.create(({next}) => { | |
const store = devtools((s, a) => a.type === "@@INIT" ? initial : a.__.apply(s)) | |
const disposeStore = store.subscribe(() => next(store.getState())) | |
const disposeActions = O.subscribe({ | |
next: a => store.dispatch(extend({}, a.value, {__: a})) | |
}, actions) | |
next(initial) | |
return () => { | |
disposeActions() | |
disposeStore() | |
} | |
}) | |
} | |
ReduxDevtoolsStorage.__culli = true // this is reserved for built-in storages only (so that we don't need to do redundant stream adapt in/out) | |
return ReduxDevtoolsStorage | |
} | |
export default ReduxDevtools |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment