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
Implement utility selectors bound to current state #5
Conversation
map(value) : | ||
(value && typeof value === 'object') ? | ||
internals.mapEachLeafFunction(value, map) : | ||
value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, huh. what cases does returning plain value
cover? is that kinda a selector to access a constant?
less a question about this PR, more about redux practice generally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't design it for any specific use-case. I wanted select
to be identical to selectors
except with any functions in there bound to state
, and that lead to me just ignoring unfamiliar values. I suppose the other option would be to strip them out for select
, but it seems like it would make app.select
and app.selectors
less "reflective" of each other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, gotcha, that makes sense. thanks for explaining! 🙏
|
||
return internals.mapEachLeafFunction(selectors, (selector) => { | ||
|
||
return (...args) => selector(getState(), ...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
baller! 🍺 ❤️
random side-thought (taking back my "only" comment 🎺 ): maybe, in the example application, show an example of composing selectors? Not directly relevant to this, just came to mind on the topic of selectors in general. squirrel braining away! |
Not sure I can picture what you're thinking of, although it reminds me of some things reselect allows you to do. Can you give an example of what you mean? |
ha, yea, it came to mind when I was reviewing the section in the redux docs on selectors and reselect as I was reviewing this, trying to better wrap my head around this. But yea, for an example, something like: const app = MiddleEnd.create({
mods: {
counter: {
selectors: {
get: ({ counter }) => counter,
// Would this work?
cone: (inc) => app.select.counter.get() + inc
}
}
}); And I'm realizing now that that might not work, binding app in there like that...hmm. But yea, that's the gist of what i had in mind. No idea how useful, if functional, though 🤷♂ |
ay, actually, on the topic of |
I would recommend using reselect for that. I don't think strange-middle-end needs to do anything special to support it. I am working on a separate library as time allows that implements selectors on normalizr entities (https://github.com/devinivy/denormie), which should work well with this library if it's ever completed. And yeah, your example above should work fine! |
ooooh very cool, thanks for the early notice. Pumped to see what comes out of that 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dig it!
Resolves #2. In short, the idea is:
app.actions
is toapp.dispatch
asapp.selectors
is toapp.select
. For former binds actions todispatch()
, and the latter bindsgetState()
to selectors.