All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.
v3.0.0 - 2017/03/24
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
v2.5.4 - 2016/09/17
Improve performance of defaultMemoize
when using custom equality check. (#170)
v2.5.3 - 2016/07/04
Reverts a Typescript change that was a breaking change. It will be reinstated in a major release. (#145)
v2.5.2 - 2016/07/03
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)
v2.5.1 - 2016/04/21
Include es directory in package.json (#117)
v2.5.0 - 2016/04/21
Add jsnext build (#116)
v2.4.0 - 2016/04/16
Add umd build (#112)
v2.3.0 - 2016/04/07
Add resultFunc
property to selectors (#92)
v2.2.0 - 2016/03/15
Add Typescript typings to package.json (#94)
v2.1.0 - 2016/03/03
Add resetRecomputations
method to selectors (#90)
v2.0.3 - 2016/02/01
Fix bug (#78) in defaultMemoize
which could cause the memoized value to be mistakenly returned for variadic functions.
v2.0.2 - 2016/01/14
Fix IE8 support by compiling in 'loose' mode
v2.0.1 - 2015/11/08
Update README and github links since move to reactjs.
v2.0.0 - 2015/10/02
Input 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.
v1.1.0 - 2015/09/16
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 - 2015/09/09
If upgrading from 0.0.2, see the release notes for v1.0.0-alpha
v1.0.0-alpha2 - 2015/09/01
src directory included in npm package js:next field added to package.json
v1.0.0-alpha - 2015/09/01
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
);
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
);
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);