|
|
|
|
|
by spanhandler
2143 days ago
|
|
Thanks for your work on it. I've found Redux super-helpful and pleasant to use for multi-platform JS UI work, in particular, to bundle HTTP client (and other network services, if not in the browser) libs behind a common, small, well-understood-by-React-devs state interface. I'm a huge fan of dependencies I can abuse—fake-up in an afternoon on unsupported platforms in another language, rip out of one place and cram in another without a fuss, stuff like that. Redux is one of the rare deps in JavaScript I never feel queazy about including in a build. I'm too out-of-the-loop these days to know what Immer is, will have to give it a look. |
|
Quick summary:
Immer is an incredibly useful immutable update library, created by Michel Weststrate (author of MobX).
It exports a single function `produce(originalState, updateCallback)`. The callback receives a `draftState` value that _looks_ like your original state, but has been wrapped in an ES6 Proxy. You can then "mutate" the draft all you want. Internally, Immer tracks all the mutations, and the final result is a safely immutably-updated value.
It drastically simplifies immutable update logic - no more nested spread operators!
See https://immerjs.github.io/immer/docs/introduction and https://redux.js.org/recipes/structuring-reducers/immutable-... .
Redux Toolkit comes with Immer built into our `createReducer` and `createSlice` APIs automatically.