Releases: reduxjs/reselect
v2.0.2
v2.0.1
v2.0.0
Breaking Changes
createSelector
, createStructuredSelector
, and custom selector creators check argument types
Input selectors are now verified to be functions during selector creation. If verification fails an error is thrown, allowing for a useful stack trace. (see #49)
There is a small chance that this could cause a breakage in existing code that contains a faulty selector that is never called.
v1.1.0
New features
createStructuredSelector
createStructuredSelector
is a convenience function that helps with a common pattern when using Reselect. The selector passed to a connect decorator often just takes other selectors and maps them to keys in an object:
const mySelectorA = state => state.a;
const mySelectorB = state => state.b;
const structuredSelector = createSelector(
mySelectorA,
mySelectorB,
mySelectorC,
(a, b, c) => ({
a,
b,
c
})
);
createStructuredSelector
takes an object whose properties are input-selectors and returns a structured selector. The structured selector returns an object with the same keys as the inputSelectors
argument, but with the selectors replaced with their values.
const mySelectorA = state => state.a;
const mySelectorB = state => state.b;
const structuredSelector = createStructuredSelector({
x: mySelectorA,
y: mySelectorB
});
const result = structuredSelector({a: 1, b: 2}); // will produce {x: 1, y: 2}
v1.0.0
v1.0.0-alpha2
New features
/src directory included in npm package
js:next field added to package.json
v1.0.0-alpha
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);