-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Allow to have slices return selectors state and derivate values #413
Comments
The issue is that we have no idea where in the state tree this slice reducer might be used. It could be at Having said that, |
@markerikson Could be possible apply the same approach to createSlice? I think the ability to get selectors and derive data is the only missing piece to be able of model domain using createSlice |
Besides it being on the same "slice" object, is there any benefit of your suggestion over just writing the selectors in the same file, one line below My reason for this question: right now, everything used in The action creators use the slice name. The reducer uses the action creators as cases. ExtraReducers need to be defined within createSlice as they need to be part of the reducer. There is nothing "passed in and out without usage" - everything is actually used and it would not work without that. From what I see, nothing in there would actually need to be defined within Also, what you are suggesting in your first post is quite the dangerous antipattern. |
@phryneas good point, in my perspective, require creating selectors for key add a lot of indirection in redux, which could be a lot of pain when you start learn it. For my the biggest benefit is avoid the indirection and be able to model a domain with all the required parts in a single place but as you said could be enough with have selector in the same file. If we can track witch data is access inside a component we could only check that values and avoid the performance issue of suscribe to all the data. Also this proposal was inspire by
|
I don't want to add any other special syntax to |
As for your other points: redux(-toolkit) and MST are conceptually very different, as they have a completely different data-flow model. Using the same approach for both is usually not a good idea. MST is a per-object approach. You call actions on one object, that object is modified. As for tracking data access, this PR might be of interest to you. |
@yeion7 @markerikson create-global-state-selector derives global state selectors from the local slice selectors based on the store signature provided.
the use case explained here also handles a paradigm issue of how should we store the global selector functions in the project folder, such that minimum change is required after some change in the |
First at all, thank for redux-toolkit ❤️
One thing that seems a lot of boilerplate for me in redux is to have a lot of selector and all the boilerplate with reselect to access the state or create derivate values
Here's a rough initial API proposal:
And inside of the component
Maybe it couldn’t be possible but in this way I think redux-toolkit could help to reduce a lot of code
What are everyone's thoughts?
The text was updated successfully, but these errors were encountered: