Would be cool if we could optionally opt-in for immer or optionally opt-out.
As middleware:
const store = createStore({
todos: {
items: ['Install easy-peasy', 'Build app', 'Profit']
}
}, {
middleware: [immerMiddleware()]
});
As a function wrapper:
const store = createStore({
todos: {
add: immer((state, payload) => {
state.items.push(payload)
})
}
});
Hey @vincentjames501 馃憢
Thanks for this suggestion. This has come up a couple of times and I am thinking that perhaps I should update the docs to reflect that the behaviour is already "opt-in", albeit not in the manner in which you suggest.
With you actions you can _either_ mutate state, or return a new immutable instance. 馃憤
const store = createStore({
todos: {
items: [],
add:(state, payload) => {
return {
...state,
items: [...state.items, payload]
};
})
}
});
Would this be ok?
I've updated the docs to reflect this. 馃憤
My thought was just so that immer could be tree-shaken away if left unused. I love the concepts in easy-peasy and I hope it gives new life to Redux!
Yeah, I don't think this will be possible as I use immer internally. :)
But don't be too scared: https://bundlephobia.com/[email protected]
:)
@ctrlplusb related question; LMK if it's better to open a new issue. (Asking in the same thread since this one is searchable.)
If we don't mutate the state and return a new instance of state, does it skip the proxy check?
@rheaditi you can do this, but to be 100% sure use the disableImmer option via the store's config. 馃憤
Most helpful comment
My thought was just so that immer could be tree-shaken away if left unused. I love the concepts in easy-peasy and I hope it gives new life to Redux!