v1.0.0-alpha
Pre-release
Pre-release
Breaking Changes
createSelectorCreator
takes a user specified memoize function instead of a custom valueEqualsFunc
.
Before
import { isEqual } from 'lodash';
import { createSelectorCreator } from 'reselect';
const deepEqualsSelectorCreator = createSelectorCreator(isEqual);
After
import { isEqual } from 'lodash';
import { createSelectorCreator, defaultMemoize } from 'reselect';
const deepEqualsSelectorCreator = createSelectorCreator(
defaultMemoize,
isEqual
);
New features
Variadic Dependencies
Selector creators can receive a variadic number of dependencies as well as an array of dependencies.
Before
const selector = createSelector(
[state => state.a, state => state.b],
(a, b) => a * b
);
After
const selector = createSelector(
state => state.a,
state => state.b,
(a, b) => a * b
);
Access ownProps
in Selector
Selector dependencies can receive a variadic number of parameters allowing a selector to receive ownProps
passed from mapToProps
in connect
.
const selector = createSelector(
(state) => state.a,
(state, props) => state.b * props.c,
(_, props) => props.d,
(a, bc, d) => a + bc + d
);
Configurable Memoize Function
import { createSelectorCreator } from 'reselect';
import memoize from 'lodash.memoize';
let called = 0;
const customSelectorCreator = createSelectorCreator(memoize, JSON.stringify);
const selector = customSelectorCreator(
state => state.a,
state => state.b,
(a, b) => {
called++;
return a + b;
}
);
assert.equal(selector({a: 1, b: 2}), 3);
assert.equal(selector({a: 1, b: 2}), 3);
assert.equal(called, 1);
assert.equal(selector({a: 2, b: 3}), 5);
assert.equal(called, 2);