Usage with Selectorator
re-reselect
accepts a selectorCreator
option which allows to replace reselects
's createSelector
with any other implementation.
import {createCachedSelector} from 're-reselect';
import createSelectoratorSelector from 'selectorator';
export function createCachedSelectorWithSelectorator(...args) {
return (polymorphicOptions = {}) => {
const options = {
selectorCreator: createSelectoratorSelector,
};
if (typeof polymorphicOptions === 'function') {
options.keySelector = polymorphicOptions;
} else {
Object.assign(options, polymorphicOptions);
}
return createCachedSelector(...args)(options);
};
}
import {createCachedSelectorWithSelectorator} from './createCachedSelectorWithSelectorator';
// selector created with single method call
const getBarBaz = createCachedSelectorWithSelectorator(
['foo.bar', 'baz'],
(bar, baz) => `${bar} ${baz}`
)(({baz}) => baz);
const state = {
foo: {bar: 'bar'},
baz: 'baz',
};
console.log(getBarBaz(state)); // "bar baz"