September 2018
Intermediate to advanced
302 pages
7h 17m
English
Since our application is not super big yet, as an exercise, let's replace Immutable.js with readonly from TypeScript:
export type TasksReducerState = { readonly entities: TaskType[], readonly isLoading: boolean, readonly hasError: boolean, readonly errorMsg: string}
This looks like a lot of repetition. We can use Readonly< T > instead:
export type TasksReducerState = Readonly<{ entities: TaskType[], isLoading: boolean, hasError: boolean, errorMsg: string}>
This looks much cleaner. However, it is not entirely immutable. You can still mutate the entities array. To prevent that, we need to use ReadonlyArray<TaskType>:
export type TasksReducerState = Readonly<{ entities: ReadonlyArray<TaskType>, // ...}>
The remaining work is to replace ...
Read now
Unlock full access