September 2018
Intermediate to advanced
302 pages
7h 17m
English
There is one place in our code that begs for simplification. Take a look at the taskSelector:
export const tasksSelector = state => state.tasks;export const tasksEntitiesSelector = createSelector( tasksSelector, tasks => (tasks ? tasks.get('entities') : null));export const getTaskById = taskId => createSelector( tasksEntitiesSelector, entities => (entities ? entities.find(task => task.id === taskId) : null));
We constantly fear whether we received something or null. This is a perfect case to delegate such work to the Maybe monad. Once we implement Maybe, the following code will be fully functional:
import Maybe from '../../../../utils/Maybe';export const tasksSelector = state => Maybe(state).map(x => x.tasks);export const ...
Read now
Unlock full access