Let's say I have the following code and let's say state
is from Redux and for some reason state
is not yet an Immutable.js object. The problem just cascades and becomes so verbose.
export const helloWorldSelector = createSelector(
initialState,
state => state.get('greetings') // yields .get is an undefined function
);
export const japaneseGreetSelector = createSelector(
helloWorldSelector,
state => state.get('ja')
);
export const englishGreetSelector = createSelector(
helloWorldSelector,
state => state.get('en')
);
I could make a fallback like so, but this still create problems for the subsequent selectors that depend on this one.
export const helloWorldSelector = createSelector(
initialState,
state => state && state.get('greetings')
);
Now if I had longer chain, then I would have to do something like this:
export const helloWorldSelector = createSelector(
initialState,
state => state && state.get('greetings', new Map())
);
This is so wet and tedious that I am starting to doubt this pattern. I must be doing something wrong, what is the correct way/best practice to use Immutable.js with Reselect?