Last active
June 16, 2017 14:33
-
-
Save joeyfigaro/8545eb37eaca66cece085e6a4d44f0dd to your computer and use it in GitHub Desktop.
Real World Ramda: Readable Redux Stores (devtools.js)
This file contains hidden or 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
// client/store/devtools.js | |
import { curry, is, ifElse, allPass, isNil, not, identity } from 'ramda'; | |
import { compose } from 'redux'; | |
import { Iterable } from 'immutable'; | |
const windowExists = is(Object, window); | |
const extensionCompose = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__; | |
const extensionComposeExists = not(isNil(extensionCompose)); | |
const isImmutable = curry(Iterable.isIterable); | |
const serializeImmutable = value => value.toJS(); | |
const defaultExtensionOptions = { | |
serialize: { | |
replacer: (key, value) => ifElse( | |
isImmutable, | |
serializeImmutable, | |
identity | |
)(value) | |
} | |
}; | |
const composeEnhancers = curry((options = defaultExtensionOptions) => { | |
return ifElse( | |
allPass(windowExists, extensionComposeExists), | |
extensionCompose(options), | |
compose | |
); | |
}); | |
export { composeEnhancers as default, defaultExtensionOptions }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment