Open rainerhahnekamp opened 6 months ago
What about a patchState which (almost) guarantees immutability?
patchState
We might also provide an overloaded version, where the action name can be provided.
I see two options:
Readonly
The state, provided via patchStatecould be a nested readonly type.
If the state is
interface FlightState { flights: Flight[]; airline: { name: string, shortcut: string }, loaded: boolean; selectedId: number; }
Following calls of patchState would fail to compile:
patchState(state, value => value.loaded = false); patchState(state, value => value.airline.name = 'AUA'); patchState(state, value => value.flights[0].id = 1); patchState(state, value => value.flights.push({id: 1}));
The other option is to use immer.
What about a
patchState
which (almost) guarantees immutability?We might also provide an overloaded version, where the action name can be provided.
I see two options:
Option 1: Deep
Readonly
The state, provided via
patchState
could be a nested readonly type.If the state is
Following calls of
patchState
would fail to compile:Option 2: Immer
The other option is to use immer.