Skip to content

Conversation

@ellbee
Copy link
Contributor

@ellbee ellbee commented Mar 11, 2016

Here's an update for the Computing Derived Data doc that I have been tinkering with for a couple of weeks. To be honest I found it pretty hard to write, any criticisms or suggested improvements are very welcome!

In the example below `mapStateToPropsFactory` creates a new `getVisibleTodos` selector, and returns a `mapStateToProps` function that has exclusive access to the new selector:

```js
const mapStateToPropsFactory = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m a bit concerned we are calling the same concept “factory” and “creator” on the same page.
Maybe we could change that to makeGetVisibleProps(), makeMapStateToProps()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, fair point.

@ellbee ellbee force-pushed the update_computing_derived_data branch from ab364c0 to d843d4b Compare March 14, 2016 07:15
export default VisibleTodoList
```

A selector created with `createSelector` only returns the cached value when its set of arguments is the same as its previous set of arguments. If we alternate between rendering `<VisibleTodoList listId="1" />` and `<VisibleTodoList listId="2" />`, the shared selector will alternate between receiving `{listId: 1}` and `{listId: 2}` as its `props` argument. This will cause the arguments to be different on each call, so the selector will always recompute instead of returning the cached value. We'll see how to overcome this limitation in the next section.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you please use instead '

@ellbee ellbee force-pushed the update_computing_derived_data branch 3 times, most recently from 04e0840 to a65b81f Compare March 14, 2016 12:40
```js
const makeMapStateToProps = () => {
const getVisibleTodos = makeGetVisibleTodos()
return (state, props) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change it here, too?

const mapStateToProps = ...
return mapStateToProps

@gaearon
Copy link
Contributor

gaearon commented Mar 14, 2016

Great work. Will merge after this last nit. Thank you very much.

@ellbee ellbee force-pushed the update_computing_derived_data branch from a65b81f to 99f6984 Compare March 14, 2016 15:26
### Motivation for Memoized Selectors

Let's revisit the [Todos List example](../basics/UsageWithReact.md):
> The examples in this section are based on the [Redux Todos List example](http://redux.js.org/docs/basics/UsageWithReact.html).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this link change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't do it on purpose, it's because of a copy paste from the reselect docs. I'll switch it back.

@ellbee ellbee force-pushed the update_computing_derived_data branch 2 times, most recently from 45acb4d to 91b03f6 Compare March 14, 2016 20:25
@ellbee ellbee force-pushed the update_computing_derived_data branch from 91b03f6 to a982b6f Compare March 14, 2016 20:29
@mxstbr mxstbr added the docs label Mar 28, 2016
@mxstbr
Copy link
Contributor

mxstbr commented Mar 28, 2016

Awesome, I reckon this is ready – really useful resource!

@mxstbr mxstbr merged commit 445183a into reduxjs:master Mar 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants