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

How to namespace selectors? #118

Open
dzintars opened this issue Aug 27, 2020 · 0 comments
Open

How to namespace selectors? #118

dzintars opened this issue Aug 27, 2020 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@dzintars
Copy link
Owner

dzintars commented Aug 27, 2020

I am looking for a patters how to correctly export selectors under some namespace. All examples i find online does not group/namespace selectors and i am not sure why is so. But is found that importing separate selectors looks kinda dirty.
One way would be to export selectors as object properties like in this example:

// INPUT/BASE SELECTORS
const getState = (state: RootState): AppNavigationState => state.appModules

// MEMOIZED SELECTORS
const selectFetchState = createSelector([getState], state => state.fetching)

export const AppNavigationSelectors = {
  selectFetchState,
}

and then to use them as AppNavigationSelectors.selectFetchState(state).
If in some component many selectors are used, then this could tidy things up.

BUT i still have some doubts... probably my overall code organization is wrong...

DzintarsToday at 12:56 PM
Is there some significant reason i don't see

export const FeatureSelectors = {
  selectFetchState,
  selectSomeEntitiesArray,
  selectCurrentEntityId,
}

used a lot in repositories? I mean, some kind of selector namespacing. As i understand, any given component typically would not use many many selectors and thus, there is no big need for namespacing them, but i'm still curious about some other reasons i am not aware of.

phryneasToday at 12:57 PM
Well, you're creating exports on top of exports there.
You've gained nothing, assuming that the file itself has one purpose and is named well. And you lost the ability to import only one thing.

DzintarsToday at 1:00 PM
You picked a right wording. I am still doubting, should i namespace them or not and... i have no clear answer why would i do so. :slight_smile:

phryneasToday at 1:00 PM
Well, your file is already your namespace.

DzintarsToday at 1:00 PM
thats true

phryneasToday at 1:00 PM
If your file is so big you need namespaces, it should probably be a folder
I should get a mug with that print 😄

DzintarsToday at 1:06 PM
Thank you. Ok... i think i got an idea... My file is not that big... I think the only reason why i "wanted" to namespace them was when i was using different features selectors in single component. In this case it "looks" cleaner MyNamespaceX.selectSomething(state) and MyNamespaceY.selectSomethingSimilaryNamed(state)...
It's not a problem for me at all ... most likely it's premature "optimizations" i am trying to kill my time on. :slight_smile:
Just researching

phryneasToday at 1:07 PM
Sounds like you have too generic variable names ^^
You can still rename these at import if they're not clear 😉

DzintarsToday at 1:08 PM
Yeah.. i know that. Ok, thank you a lot... you just solved some of my doubts :slight_smile:

@dzintars dzintars added the question Further information is requested label Aug 27, 2020
@dzintars dzintars self-assigned this Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant