-
Notifications
You must be signed in to change notification settings - Fork 672
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
Question: Can I nest one selector inside result function of another selector? #360
Comments
Technically, you can do that, but it will then always recompute on every state change since Instead of creating a selector using const itemKeyReifierSelector = createSelector(
// selectors which select state slices that the computor depends on.
state => state.path.to.dep0,
state => state.path.to.dep1,
selectorThatSelectsDep2,
// and of course, the computor down here.
(dep0, dep1, dep2) =>
// NOTE: This computed function will change any time
// one of the deps changes,
(itemKey) => getItemFromDeps(itemKey, dep0, dep1, dep2)
)
export default createSelector(
itemsSelector,
// No need to pass in `state` directly, itemKeyReifierSelector
// handles binding state slices to a function.
itemKeyReifierSelector,
// NOTE: The $ prefix is what I use to signal a derived function.
// It is not necessary.
(items, $itemKeyReifier) =>
items.map($itemKeyReifier)
) UPDATE 2019-09-30: Edited |
This pattern doesn't work... when you call itemKeyReifierSelector(itemKey), it'll pass the first argument as the state argument. your state won't be available to the selector unless you actually pass in the state. |
The pattern does work, however the sketch that I wrote out was not clear. I have updated the sketch to show the actual intent. |
Oh, I am seeing where I went wrong. I was calling the Thanks so much! |
Hey folks, I'm having a bit of trouble understanding the example you gave. |
Did anybody find a solution to above? I am also getting confused about what |
Hi there! Can I nest one selector inside result function of another selector? Would every instance of nested selector be memoized?
example:
The text was updated successfully, but these errors were encountered: