-
Notifications
You must be signed in to change notification settings - Fork 46
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
Support features from [email protected] #60
Conversation
…ny number of uniform selectors
Hi @sgrishchenko, thanks for your massive PR! I'll try to split it up into different units to better understand what it introduces and if it needs any refinement. I will dive into the code in a second moment. I need a few more time, for that. I understand that the PR introduces the following 3 elements:
Side NoteIf you have time, It'd be very helpful having the the commits of this PR split by feature more o less like the list above. 😸 selector.dependenciesNew reselect v4 feature: reduxjs/reselect#251 selector.recomputations / resetRecomputationsThis one is an old It's a property exposed for testing purpose. Since it's currently possible to retrieve the cached TS typingsAdd relevant typings for:
TS typings: heterogeneous selectorsI found I bit hard to understand what's happened here. Looking forward to hearing back from you! ✋ |
Now the changes are already divided into 2 commit:
I think that the dependency feature is too small to put it into a separate commit. Significative Testing Case For RecomputationsFor example, how to check that the selector is recalculated only twice with this variant of the call: const mySelector = ...
mySelector(state, { prop: 'val1' })
mySelector(state, { prop: 'val2' })
mySelector(state, { prop: 'val1' })
mySelector(state, { prop: 'val2' }) If you will use regular reselect selector, you will see next: console.log(mySelector.recomputations()) // => 4 But if you will use re-reselect selector, you will see:
As you can see, I rewrote all the tests for using recomputations instead of Heterogeneous SelectorsFor example, you have a very large project (maybe even a mono-repo). And each module does not know the full state interface. // in first module
type FirstStateSegment = {
firstState: ...
}
const firstSelector = (state: FirstStateSegment) => state.firstState
// in second module
type SecondStateSegment = {
secondState: ...
}
const secondSelector = (state: SecondStateSegment) => state.secondState And you need to write an integration module that uses the first module and the second module and their selestors. // in third module
const thirdSelector = createCachedSelector(
firstSelector,
secondSelector,
(firstState, secondState) => ...
) Previously, from the point of view of typing, all selectors should have the same type of state. Heterogeneous selectors remove this restriction and now it is possible to create such selectors as the |
Thanks for the additional info, @sgrishchenko! New featuresI'd definitely go for introducing Heterogeneous Selectors typingsAs for "Heterogeneous Selectors" typings, I get the reason of it, but I'm afraid that adding 4000 lines of type definition to a 100 loc library might not be the best decision in terms of maintainability. I've not much experience with TS but I understand that the main reason of such verbosity are the expressive limitations of the typing system itself, right? I'd personally suggest to move the new Heterogeneous Selectors typings to a separate PR and reason about it from there. Maybe @xsburg ( 🙌) has something to say about it. Reselect v4 dependencyDo we actually need forcing our consumers to use reselect v4? The new features might be implemented no matter of the reselect version. I'd like our users not to be forced to switch to a newer version of Reselect if not strictly needed. :) Thanks again! |
About performance implications: I had thought to disable recomputations in the production mode, but I looked at the implementation in the reselect and saw that they did not do that, and I decided not to make premature optimization. About Heterogeneous Selectors typings: I am also not happy with everything in the current approach to typing and I have ideas how to reduce typing by about 4 times. But I decided not to do it yet to keep the analogy with the reselect. In the future, I plan to improve the typing in the reselect, and if my decision takes root, transfer this decision to this library. The idea is that non-parameterized selectors are a special case of parameterized selectors, and homogeneous selectors are special cases of heterogeneous selectors. But while in the current implementation to reduce the amount of code fails. If you look at the typing of a reselect, there are similar problems (although there are fewer lines because they do not use a prettier). About separate PR: In short, I can not do it. The reason is that heterogeneous selectors now contain elements of the dependencies feature, but at this stage I have no guarantees that the dependencies feature will go to the library. It turns out that I need to make two pull requests: the first with features of heterogeneous selectors, the second with the addition of dependencies to heterogeneous selectors. I think all this will greatly delay the process, while users are already using heterogeneous selectors in the reselect, and I think it will be uncomfortable for them to find out that the re-reselect has not this feature. About forcing to use reselect v4: I do not force). I only changed the dev dependency. Peer dependency remains the same and requires a reselect above the first version. |
I see your points, now, thank you. I'd split your PR into 2 different PR's in order to be able to publish:
Would you agree with this plan? |
Ok, thank you |
…rs and any number of uniform selectors" This reverts commit ef8d5a4
… selectors and any number of uniform selectors"" This reverts commit 426a7c6
Superseded by #62 and #63. Thank you @sgrishchenko! |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
feature
What is the new behaviour?
supported recomputations and dependencies
see https://github.com/reduxjs/reselect/releases/tag/v4.0.0
Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
I think so, because the reselect for similar changes made it.
Other information:
Please check if the PR fulfills these requirements: