All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.
Performance improvements (thanks to @johnhaley81)
Updated Typescript typings (thanks to everyone who helped)
For performance reasons, a selector is now not recalculated if its input is equal by reference (===
).
import { createSelector } from 'reselect';
const mySelector = createSelector(
state => state.values.filter(val => val < 5),
values => {
console.log('calling..')
return values.reduce((acc, val) => acc + val, 0)
}
)
var createSelector = require('./dist/reselect.js').createSelector;
const mySelector = createSelector(
state => state.values.filter(val => val < 5),
values => {
console.log('calling..')
return values.reduce((acc, val) => acc + val, 0)
}
)
var state1 = {values: [1,2,3,4,5,6,7,8,9]};
console.log(mySelector(state1));
state1.values = [3,4,5,6,7,8,9];
console.log(mySelector(state1));
var state2 = {values: [1,2,3,4,5,6,7,8,9]};
console.log(mySelector(state2));
var state3 = {values: [3,4,5,6,7]};
console.log(mySelector(state3));
calling..
10
calling..
7
calling..
10
calling..
7
calling..
10
10
calling..
10
calling..
7
Improve performance of defaultMemoize
when using custom equality check. (#170)
Reverts a Typescript change that was a breaking change. It will be reinstated in a major release. (#145)
When a selector uses defaultMemoize, if an exception is thrown for a set of arguments then the selector should also throw when called again with those arguments. (#144)
Include es directory in package.json (#117)
Add jsnext build (#116)
Add umd build (#112)
Add resultFunc
property to selectors (#92)
Add Typescript typings to package.json (#94)
Add resetRecomputations
method to selectors (#90)
Fix bug (#78) in defaultMemoize
which could cause the memoized value to be mistakenly returned for variadic functions.
Fix IE8 support by compiling in 'loose' mode
Update README and github links since move to reactjs.
createSelector
, createStructuredSelector
, and custom selector creators check argumentsInput selectors are now verified to be functions during selector creation. If verification fails an error is thrown, allowing for a useful stack trace
There is a small chance that this could cause a breaking change in code that contains a faulty selector that is never called.
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}
If upgrading from 0.0.2, see the release notes for v1.0.0-alpha
src directory included in npm package js:next field added to package.json
createSelectorCreator
takes a user specified memoize function instead of a custom valueEqualsFunc
.
import { isEqual } from 'lodash';
import { createSelectorCreator } from 'reselect';
const deepEqualsSelectorCreator = createSelectorCreator(isEqual);
import { isEqual } from 'lodash';
import { createSelectorCreator, defaultMemoize } from 'reselect';
const deepEqualsSelectorCreator = createSelectorCreator(
defaultMemoize,
isEqual
);
Selector creators can receive a variadic number of dependencies as well as an array of dependencies.
const selector = createSelector(
[state => state.a, state => state.b],
(a, b) => a * b
);
const selector = createSelector(
state => state.a,
state => state.b,
(a, b) => a * b
);
ownProps
in SelectorSelector 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
);
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);