reselect
reselect copied to clipboard
createSelector fail silently ?
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?
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
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
Cool, no problem