I think I may have misunderstood what immer provides. My intention was to use immer to make the state objects immutable so that if I inadvertently bind a two-way or some other input directly to the state, then I’ll get an error (then I’ll fix it).
If I don’t do:
then the above happens if I don’t create a temp copy of my state in the vm when attaching the state directly to an edit input, then it throws an error like:
aurelia-binding.js:1409 Uncaught TypeError: Cannot assign to read only property 'name' of object '#<Object>'
Good. That is what I think I was expecting to happen. But if I leave autoFreeze turned on, then I am bombarded by the warnings in the console from Aurelia (and not just for two-way binds, I get that as soon as I do something like bind to a custom element (which should bind one-way?)
WARN [property-observation] Cannot observe property ‘name’ of object
Not so good. Those would potentially mask other warnings.
And then, in the immer docs, I see that:
Immer automatically freezes any state trees that are modified using produce. This protects against accidental modifications of the state tree outside of a producer. This comes with a performance impact, so it is recommended to disable this option in production. It is by default enabled. By default it is turned on during local development, and turned off in production. Use setAutoFreeze(true / false) to explicitly turn this feature on or off.
So not sure what immer is doing for me in production if that immutability is turned off?