Reselect: Composed selectors require function calls, not function names, as parameters?

Created on 13 Feb 2017  路  1Comment  路  Source: reduxjs/reselect

Hello, please see code example below and the arguments to createSelector in getFruitNames() and getAltFruitNames(). I haven't seen any example that explains why the last function is correct:

import { createSelector } from 'reselect';
import { fromJS } from 'immutable';

const state = fromJS({
  tree: {
    fruit: [
      { name: 'apple' },
    ],
  }
});

const getTree = (state) => state.get('tree');

const getFruit = () => createSelector(
  getTree,
  (tree) => tree.get('fruit')
);

const getFruitNames = () => createSelector(
  getFruit, // function name
  (fruit) => {
    console.log(fruit); // Selector class object -> NOT OK!
    return fruit.map((f) => f.get('name'));
  }
);

const getAltFruitNames = () => createSelector(
  getFruit(), // <-- function call?!
  (fruit) => {
    console.log(fruit); // Immutable.List object -> OK!
    return fruit.map((f) => f.get('name'));
  }
);

Reselect: 2.5.4

Most helpful comment

const getFruit = () => createSelector(... creates a function that returns a selector. None of those () => should be there, just const selectorName = createSelector(....

>All comments

const getFruit = () => createSelector(... creates a function that returns a selector. None of those () => should be there, just const selectorName = createSelector(....

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jEnbuska picture jEnbuska  路  6Comments

sarink picture sarink  路  4Comments

vjau picture vjau  路  5Comments

clementdevos picture clementdevos  路  4Comments

loick picture loick  路  3Comments