-
Notifications
You must be signed in to change notification settings - Fork 176
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
Add Redux selectors for all state accesses #1966
Comments
@MaximusHaximus I will start with it soon. Just a thought. What do you think about moving the selectors into separate files? I mean when I looked into this file: |
The selectors directly read data from the reducer state and shouldn't really have any other external dependencies, so I think that co-locating them in the same file is convenient and relevant. Now that we are creating "slices" using redux-toolkit's Essentially, by using This means that in almost every case (all cases where we don't have multiple reducers that react to the same action, which should be very rare), we can define everything (actions, reducers, selectors and thunks) relating to a particular domain in the same Right now the slice file exports:
Named exports
Selectors names are prefixed with That being said, while I think it makes a lot of sense to keep the selectors co-located with the state (reducers) that they primarily select from, there are two things that our current first implemented slice exports directly from the A. Cross-domain thunks
Since I don't have a good handle on if or how often these 2 cases will happen in practice for our codebase, and cross-cutting actions are strongly discouraged in general, I defaulted towards co-locating the things in the same file with the intention to only extract them into separate files/directories if we need to due to either (A) or (B) above :) cc: @Patrick1904 @esaminu Feedback/suggestions welcome; this is where we get to make all the decisions about how our new and shiny redux-slice-based state will be structured at the codebase level :) |
I like the domain driven file structure this will encourage 👍 While cross domain thunks and and cross cutting thunks might not be as common, I think cross domain selectors will be very common since I expect we'll often want to compute a value from different parts of the state tree to display things in a certain way or decide what to render. How we group cross cutting actions, selectors and thunks will end up being the bottom line here. Other notes / opinions on this approach:
|
Agreed! We've already got cross-cutting selectors (things that need
There are essentially two types of async thunks:
I think that we'll still want to use
|
Blocks #1239
PROBLEM:
Currently, we access redux state using direct references to the entire state tree/structure. For example, rather than having a selector
getActiveAccountId()
, we have a direct reference tostate.account.accountId
inProfile.js
.Using direct references has several drawbacks:
state.xxx.xxx.xxx
all the way to the child data. As a result, trying to find all places that reference a specific piece of data is challenging and error prone. By always using selectors to select logically identical data from the store, we can easily audit every component that is linked to that piece of data with a single, unique string (the name of the selector)SOLUTION:
We should always use selectors to load data from our Redux store, with no exceptions.
The text was updated successfully, but these errors were encountered: