reselect icon indicating copy to clipboard operation
reselect copied to clipboard

Add alias for createStructuredSelector?

Open ellbee opened this issue 10 years ago • 9 comments

From an issue on React Redux @slorber wrote:

Also I'm surprised that you comment positively on this because I've just discovered "structured selectors" of Reselect. I don't find the name very good but it was built after your issue and seems to almost do what I propose here...

I was never entirely happy with the name createStructuredSelector. If we can come up with a more descriptive name that would make structured selectors more discoverable then we could make an alias for it. If anyone has any suggestions I'd love to hear them.

ellbee avatar Jul 06 '16 17:07 ellbee

createSelectorFromSpec?

jimbolla avatar Jul 06 '16 17:07 jimbolla

Thanks for the suggestion @jimbolla. I think it is along the right lines. I wonder if we can be more explicit than "Spec" though. createSelectorFromObjectShape? createSelectorWithObjectShape? They are longer than I'd ideally like.

ellbee avatar Jul 07 '16 19:07 ellbee

how about

  • createSelectorMap - since the resulting 'structure' is map-likekey: selector
  • mapSelectors - since it maps selectors to keys in an object

justingreenberg avatar Aug 10 '16 20:08 justingreenberg

createSelectorMap seems not so bad. However we are just creating a selector. Couldn't we also make an overload of createSelector and detect at runtime the only param is actually a map of name -> function ?

Or maybe something like Redux? combineSelectors?

slorber avatar Aug 11 '16 09:08 slorber

@justingreenberg createSelectorMap is pretty good

@slorber

createSelectorMap seems not so bad. However we are just creating a selector. Couldn't we also make an overload of createSelector and detect at runtime the only param is actually a map of name -> function ?

That was the original proposal, but there was concern that it wasn't explicit enough. I don't have strong objections to making it work that way, and I think its worth considering. One potential problem is that createSelector seems pretty hard to type (although I am an amateur with Flow and probably missing something) and I suspect this change would make it harder still.

ellbee avatar Aug 11 '16 20:08 ellbee

I don't know enough Flow to say. That seems strange if Flow can't handle overloads like that as they are supported by many languages however.

slorber avatar Aug 12 '16 08:08 slorber

I like combineSelectors. It mirrors combineReducers in Redux.

mindjuice avatar Aug 12 '16 21:08 mindjuice

+1 for combineSelectors especially since searching this project for combineReducers brought me to @mindjuice's comment above. (…as the only result, I would add! Perhaps a nod to the similarity could be added to the documentation, whatever the new alias actually ends up being called.)

natevw avatar Aug 23 '16 20:08 natevw

In the meantime, if using ES6, one can simply import { createStructuredSelector as combineSelectors } from 'reselect'.

natevw avatar Aug 23 '16 22:08 natevw