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

The last example says it can't be written in Reselect, but it can. #15

Closed
todorpr opened this issue Feb 27, 2021 · 2 comments · Fixed by #18
Closed

The last example says it can't be written in Reselect, but it can. #15

todorpr opened this issue Feb 27, 2021 · 2 comments · Fixed by #18

Comments

@todorpr
Copy link

todorpr commented Feb 27, 2021

I just discovered proxy-memoize recently I think it has a good potential.

One thing I think is incorrect is the statement that the last example can't be written in reselect

The last example is this one:

const todoTextsSelector = memoize(state => state.todos.map(todo => todo.text));

Here is how I see it in reselect:

const state = {
  todos: [{ text: 'aaa' }, { text: 'bbb' }]
}

const todoTextSelector = createSelector(
  state => state.todos,
  todos => todos.map(todo => todo.text)
)

console.log(todoTextSelector(state)) // ["aaa", "bbb"]
console.log(todoTextSelector(state)) // ["aaa", "bbb"]
console.log(todoTextSelector(state)) // ["aaa", "bbb"]
console.log(todoTextSelector(state)) // ["aaa", "bbb"]
console.log(todoTextSelector.recomputations()) // 1
@dai-shi
Copy link
Owner

dai-shi commented Feb 27, 2021

Thanks for jumping in.

My apologies, that was too easy without detailed info.

const state = {
  todos: [{ text: 'aaa', completed: true }, { text: 'bbb', completed: false }]
}

We assume this case, and when only completed is changed.

Please refer this too: reduxjs/react-redux#1653 (comment)

@todorpr
Copy link
Author

todorpr commented Feb 27, 2021

Aha, now I get it. You are absolutely right - reselect's selector will recompute in this case, whereas memoize's won't.

Noitidart added a commit to Noitidart/proxy-memoize that referenced this issue Apr 3, 2021
dai-shi pushed a commit that referenced this issue Apr 3, 2021
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 a pull request may close this issue.

2 participants