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

Not being passed resolved arguments to resolver function #2

Closed
tim-field opened this issue Mar 14, 2017 · 1 comment
Closed

Not being passed resolved arguments to resolver function #2

tim-field opened this issue Mar 14, 2017 · 1 comment

Comments

@tim-field
Copy link

tim-field commented Mar 14, 2017

import createCachedSelector from 're-reselect';
import { createSelector } from 'reselect';
import { orderBy } from 'lodash/collection';

const entitiesSelector = createSelector(
  selectGlobal,
  (state) => state.get('entities')
);

const pathArgSelector = (state, { path }) => path;

const entitiesPathSelector = createSelector(
  entitiesSelector,
  pathArgSelector,
  (entities, path) => entities.get(path)
);

const sortBySelector = (state, { sortBy }) => sortBy;
const sortOrderSelector = (state, { sortOrder }) => sortOrder;

const entitiesSortedSelector = createCachedSelector(
  entitiesPathSelector,
  sortBySelector,
  sortOrderSelector,
  (entities, sortBy, sortOrder) => {
    const cacheKey = `${entities.hashCode()}:${sortBy}:${sortOrder}`;
    console.log('resolver', cacheKey); //  resolver -181045611:id:desc
    console.log('no cache for ', sortBy, sortOrder); //  no cache for  id desc
    return orderBy(entities.toList().toJS(), getSortIteratee(sortBy), sortOrder);
  }
)((entities, { sortBy, sortOrder }) => { 
  // NOTE here I'm actually getting passed my original state object! 
  const cacheKey = `${entities.hashCode()}:${sortBy}:${sortOrder}`;
  console.log('cached selector', cacheKey);  // cached selector 403733751:id:desc
  return cacheKey;
})

Called like so in container.

const mapStateToProps = (state, props) => ({
  entities: entitiesSortedSelector(state, {
    path: props.entities, // ~ 'posts' 
    sortBy: props.sortBy || EntityQuery.defaultProps.sortBy,
    sortOrder: props.sortOrder || EntityQuery.defaultProps.sortOrder,
  }),
});
@tim-field tim-field changed the title What's happening here Not being passed resolved arguments to resolver function Mar 14, 2017
@tim-field
Copy link
Author

Sorry, I need RTFM, one of those days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant