reselect icon indicating copy to clipboard operation
reselect copied to clipboard

createSelector fail silently ?

Open qingweibinary opened this issue 10 years ago • 3 comments

Hi, I just started to use Reselect and found it seems to fail silently when call createSelector.

Example

const tickAssetFilter = (assets, contracts) => {
    console.log('f', assets.filter);        // undefined
    const tickAssets = assets.filter(a => {
    ......


createSelector(
    fullTradesSelector,
    trade => {
        const tickAssets = tickAssetFilter(trade.assets, trade.contracts);
        const cloneTrade = trade;
        cloneTrade.assets = tickAssets;
        return cloneTrade;
    }
);

assets.filter does not exists, I would expect

Uncaught TypeError: s.filter is not a function(…)

but nothing is shown instead, and the Component not construct at all

Is this a design decision or a bug?

qingweibinary avatar Jan 21 '16 01:01 qingweibinary

Hi, I'm not sure I understand the problem. The following works as I would expect:

import { createSelector } from 'reselect'

const mySelector = createSelector(
  state => state.assets,
  assets => {
    return assets.filter(x => x > 2)
  }
)

const state = {
  assets: [1,2,3,4],
  contracts: ['a', 'b', 'c'],
}

console.log(mySelector(state)) // [3, 4]

const state2 = {
  contracts: ['a', 'b', 'c'],
}

console.log(mySelector(state2)) // ERROR: cannot read property filter of undefined 

ellbee avatar Jan 21 '16 07:01 ellbee

Hi @ellbee , you understand correctly ~

Thanks for your reply. Seems something in my browser or application is catching all these errors ~

Sorry for the trouble, I'll close it

qingweibinary avatar Jan 21 '16 08:01 qingweibinary

Cool, no problem

ellbee avatar Jan 21 '16 09:01 ellbee