Skip to content

Instantly share code, notes, and snippets.

@joeyfigaro
Last active June 16, 2017 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeyfigaro/8545eb37eaca66cece085e6a4d44f0dd to your computer and use it in GitHub Desktop.
Save joeyfigaro/8545eb37eaca66cece085e6a4d44f0dd to your computer and use it in GitHub Desktop.
Real World Ramda: Readable Redux Stores (devtools.js)
// 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