Feature request: prop values selector
A common pattern I find when composing selectors is to do something like this:
var myItem = createSelector(
itemOne,
itemTwo,
itemThree,
(itemOne, itemTwo, itemThree) => ({itemOne, itemTwo, itemThree})
)
It'd be a little cleaner if we could do:
var myItem = createSelector({itemOne, itemTwo, itemThree})
Where reselect would recognize the first arg is an object, pick the values off and spread those into the arguments, and then remap the result values of these functions to the keys.
var myItem = createSelector({
keyOne: selectorForSome('value'),
keyTwo
})
myItem(state) === {keyOne: value, keyTwo: value}
If this seems outside the scope of the lib, I can write it as a plugin, just thought I'd bring it up as a common pattern I've found useful.
Interesting. I think I quite like this. It would be backwards compatible, so no problems there. I know some people like the explicitness of the library as it currently is, but in that case they could just ignore this feature. I would be interested to hear the thoughts of others.
Curious, how would it be backwards incompatible?
Ha, sorry I meant it won't be backwards incompatible!
Ah gotcha! :)
BTW, been using this quite a bit and it's pretty great, would love to see it added :)
Cool, glad to hear its working for you. Now I have got 1.0.0 released this is next on the list.
@speedskater @faassen Any objections to this?
@ellbee @tgriesser I like the idea but I would suggest creating explicit explicit method for this. We have already such a function. It is called composeSelectors, works on top of reselect and exactly has your suggested behaviour. I think we should add it as a feature. @PSpSynedra already implemented it together with tests. What to you think about it?
Having it as a seperate function adds really nice syntax for composeability and some kind of named parameters. like this:
var itemSum = createSelector(composeSelectors({item1, item2, item3}), items => items.item1 + items.item2 + items.item3);
@speedskater @PSpSynedra That sounds good to me. Do you want to make a PR?
@ellbee Yes, will create it tomorrow.
@PSpSynedra Awesome, thank you!
This functionality has been added to Reselect v1.1.0 with the new function createStructuredSelector