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

Selectors inside a resolver, as args alone might not be enough to key #3

Closed
tim-field opened this issue Mar 14, 2017 · 2 comments
Closed
Labels

Comments

@tim-field
Copy link

tim-field commented Mar 14, 2017

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 ?

@toomuchdesign
Copy link
Owner

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 inputSelectorsand 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.

@tim-field
Copy link
Author

Thanks for putting this library together, its working well!

Repository owner locked and limited conversation to collaborators Aug 2, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants