Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename defaultMemoize to lruMemoize #654

Merged
merged 13 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 56 additions & 54 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# Change log

All notable changes to this project will be documented in this file.
Changes in this project are primarily documented in the Github release notes:

- https://github.com/reduxjs/reselect/releases

Changes from v4.0.0 and earlier are documented in this file

This project adheres to [Semantic Versioning](http://semver.org/).

## [v4.0.0](https://github.com/reduxjs/reselect/releases/tag/v4.0.0) - 2018/09/30

### New Features

Exposed selector dependencies (#251)
Use provided memoize function for selectors (#297)
Use provided memoize function for selectors (#297)

### Breaking Changes

Updated TypeScript typings (#274, #315)
Updated TypeScript typings (#274, #315)

## [v3.0.0](https://github.com/reduxjs/reselect/releases/tag/v3.0.0) - 2017/03/24

Expand All @@ -28,7 +33,7 @@ For performance reasons, a selector is now not recalculated if its input is equa
#### Example:

```js
import { createSelector } from 'reselect';
import { createSelector } from 'reselect'

const mySelector = createSelector(
state => state.values.filter(val => val < 5),
Expand All @@ -38,7 +43,7 @@ const mySelector = createSelector(
}
)

var createSelector = require('./dist/reselect.js').createSelector;
var createSelector = require('./dist/reselect.js').createSelector

const mySelector = createSelector(
state => state.values.filter(val => val < 5),
Expand All @@ -48,14 +53,14 @@ const mySelector = createSelector(
}
)

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));
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))
```

#### Output in v2.5.4:
Expand Down Expand Up @@ -171,36 +176,36 @@ There is a small chance that this could cause a breaking change in code that con

#### `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:
`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:

```js
const mySelectorA = state => state.a;
const mySelectorB = state => state.b;
const mySelectorA = state => state.a
const mySelectorB = state => state.b

const structuredSelector = createSelector(
mySelectorA,
mySelectorB,
mySelectorC,
(a, b, c) => ({
a,
b,
c
})
);
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.

```js
const mySelectorA = state => state.a;
const mySelectorB = state => state.b;
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}
const result = structuredSelector({ a: 1, b: 2 }) // will produce {x: 1, y: 2}
```

## [v1.0.0](https://github.com/reduxjs/reselect/releases/tag/v1.0.0) - 2015/09/09
Expand All @@ -225,22 +230,19 @@ js:next field added to package.json
#### Before

```js
import { isEqual } from 'lodash';
import { createSelectorCreator } from 'reselect';
import { isEqual } from 'lodash'
import { createSelectorCreator } from 'reselect'

const deepEqualsSelectorCreator = createSelectorCreator(isEqual);
const deepEqualsSelectorCreator = createSelectorCreator(isEqual)
```

#### After

```js
import { isEqual } from 'lodash';
import { createSelectorCreator, defaultMemoize } from 'reselect';
import { isEqual } from 'lodash'
import { createSelectorCreator, defaultMemoize } from 'reselect'

const deepEqualsSelectorCreator = createSelectorCreator(
defaultMemoize,
isEqual
);
const deepEqualsSelectorCreator = createSelectorCreator(defaultMemoize, isEqual)
```

### New features
Expand All @@ -255,7 +257,7 @@ Selector creators can receive a variadic number of dependencies as well as an ar
const selector = createSelector(
[state => state.a, state => state.b],
(a, b) => a * b
);
)
```

#### After
Expand All @@ -265,7 +267,7 @@ const selector = createSelector(
state => state.a,
state => state.b,
(a, b) => a * b
);
)
```

#### Access `ownProps` in Selector
Expand All @@ -274,32 +276,32 @@ Selector dependencies can receive a variadic number of parameters allowing a sel

```js
const selector = createSelector(
(state) => state.a,
state => state.a,
(state, props) => state.b * props.c,
(_, props) => props.d,
(a, bc, d) => a + bc + d
);
)
```

#### Configurable Memoize Function

```js
import { createSelectorCreator } from 'reselect';
import memoize from 'lodash.memoize';
import { createSelectorCreator } from 'reselect'
import memoize from 'lodash.memoize'

let called = 0;
const customSelectorCreator = createSelectorCreator(memoize, JSON.stringify);
let called = 0
const customSelectorCreator = createSelectorCreator(memoize, JSON.stringify)
const selector = customSelectorCreator(
state => state.a,
state => state.b,
(a, b) => {
called++;
return 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);
)
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)
```
Loading
Loading