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

Memoize prop transformation functions and specify their arguments #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

naw
Copy link

@naw naw commented Nov 6, 2015

Meant to be similar to reselect's createSelector, but instead of
reaching into redux state, it reaches into the component's this.

@jgautsch I tried to make reselect work inside the component, but reselect expects inputSelectors, which are functions that map state to inputs, and then pass those inputs to the transformation function.

Instead, we need to be able to map things already inside the component (such as this.props.something or this.someOtherDerivedData) into inputs that are passed to the transformation function.

There might be a way to clean up the API a little, but for now, it's pretty similar to reselect.

Meant to be similar to reselect's `createSelector`, but instead of
reaching into redux `state`, it reaches into the component's `this`.
@naw
Copy link
Author

naw commented Nov 6, 2015

@jgautsch I added a "search" feature to the basic todo app in order to demonstrate composition of derived data.

visibleTodos are todos that match the visibility filter (i.e. completed, uncompleted, or all)

matchingTodos are visibleTodos that also match the text search string.

When you change the text search, matchingTodos() is recalculated (by filtering visibleTodos), but visibleTodos does not have to be recalculated --- it just uses the memoized result.

When you add a new todo, you have to recalculate the visibleTodos(), which also triggers matchingTodos() to be recalculated, since it depends on visibleTodos().

@naw
Copy link
Author

naw commented Nov 6, 2015

webpack can't seem to compile this since I moved it into its own repo. Not sure off hand why, probably something with ES6 vs ES7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants