Skip to content

Commit

Permalink
v2.4.1
Browse files Browse the repository at this point in the history
* chore(deps): update to lodash to 4.17.15
* chore(deps): update proptypes to 15.7.2
* docs(integrations): add docs for how to reference data from state for reselect selectors - #614
  • Loading branch information
prescottprue committed Sep 5, 2019
1 parent c1b1b89 commit 78171b9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ View docs for recipes on integrations with:

* [redux-firestore](http://react-redux-firebase.com/docs/firestore.html)
* [redux-thunk](http://react-redux-firebase.com/docs/integrations/thunks.html)
* [reselect](http://react-redux-firebase.com/docs/integrations/integrations/reselect.html)
* [redux-observable](http://react-redux-firebase.com/docs/integrations/redux-observable.html)
* [redux-saga](http://react-redux-firebase.com/docs/integrations/redux-saga.html)
* [redux-form](http://react-redux-firebase.com/docs/integrations/redux-form.html)
Expand Down
1 change: 1 addition & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* [Integrations](/docs/integrations/README.md)
* [Redux Thunk](/docs/integrations/thunks.md)
* [Redux Form](/docs/integrations/redux-form.md)
* [Reselect](/docs/integrations/reselect.md)
* [Redux Persist](/docs/integrations/redux-persist.md)
* [Redux Saga](/docs/integrations/redux-saga.md)
* [Redux Observable](/docs/integrations/redux-observable.md)
Expand Down
32 changes: 32 additions & 0 deletions docs/integrations/reselect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Reselect

There are a number of reasons to use state selectors, as mentioned in the [relesect docs](https://github.com/reduxjs/reselect):

> * Selectors can compute derived data, allowing Redux to store the minimal possible state.
> * Selectors are efficient. A selector is not recomputed unless one of its arguments changes.
> * Selectors are composable. They can be used as input to other selectors.
For more information, about why this is important, checkout the [motivation for memoized selectors sections of the reselect docs](https://github.com/reduxjs/reselect#motivation-for-memoized-selectors)

## State Selectors

Select only what you need from state in your selectors instead of the whole firebase/firestore state object:

```js
import { createSelector } from 'reselect';
import { connect } from 'react-redux'
import { get, sumBy } from 'lodash'

const netTotalSelector = createSelector(
state => get(state, 'firestore.data.products'),
products => sumBy(products, 'price')
)

connect((state) => ({
netTotal: netTotalSelector(state)
}))(Component)
```

In this case Reselect will memoize the products object. That means that even if there's any update to other parts of redux state (including firebase/firestore), the memoized products object will stay the same until there is an update to the products themselves.

See [issue #614](https://github.com/prescottprue/react-redux-firebase/issues/614) for more info.
30 changes: 21 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-redux-firebase",
"version": "2.4.0",
"version": "2.4.1",
"description": "Redux integration for Firebase. Comes with a Higher Order Components for use with React.",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down Expand Up @@ -59,8 +59,8 @@
],
"dependencies": {
"hoist-non-react-statics": "^3.3.0",
"lodash": "^4.17.11",
"prop-types": "^15.6.2"
"lodash": "^4.17.15",
"prop-types": "^15.7.2"
},
"peerDependencies": {
"react": "^0.14.6 || ^15.0.0-0 || ^16.0.0-0"
Expand Down

0 comments on commit 78171b9

Please sign in to comment.