Selectors inside a resolver, as args alone might not be enough to key
tim-field opened this issue · 2 comments
Hey I've posted two dumb issues today, lets go for three. ;)
Is this on the right track?
const entitiesSortedSelector = createCachedSelector(
entitiesPathSelector,
sortBySelector,
sortOrderSelector,
(entities, sortBy, sortOrder) =>
orderBy(entities.toList().toJS(), getSortIteratee(sortBy), sortOrder);
)((state, { path, sortBy, sortOrder }) => {
const entities = entitiesPathSelector(state, { path });
return `${entities.hashCode()}:${sortBy}:${sortOrder}`;
});
I initially hoped that the resolver function would recieve the same args as the resolved function ( issue #2), if it doesn't then I really want to check that I'm dealing with the same entities collection here ( path param alone isn't enough )
Is the code above a correct path to take ?
The resolverFunction
receives the same arguments as the final selector function (and as reselect's inputSelectors
, too).
In your example, the resolverFunction
:
(state, { path, sortBy, sortOrder }) => {
const entities = entitiesPathSelector(state, { path });
return `${entities.hashCode()}:${sortBy}:${sortOrder}`;
}
...should receive the same arguments as entitiesPathSelector
, sortBySelector
and sortOrderSelector
.
Back to your example, it looks ok: you've got reselect's inputSelectors
and resultFunc
and re-reselect's resolverFunction
in place.
Just check that resolverFunction
arguments the same as entitiesPathSelector
, sortBySelector
and sortOrderSelector
.
(re-)reselect API's are quite hard at first sight.
Thanks for putting this library together, its working well!