aurelia / documentation

The documentation for Aurelia.
MIT License
105 stars 111 forks source link

Remove reference to, or even warn about, using immer and binding with aurelia-store #478

Open NightWulfe opened 4 years ago

NightWulfe commented 4 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior: The Aurelia documentation guide for "Managing App State" demonstrates binding state properties directly in templates. The documentation then indicates that readers should review the Immer library to assist with ensuring their state remains immutable, implying that Immer is compatible with Aurelia when used in this way.

However, actually attempting to use Immer with Aurelia while binding directly to the store state results in the error "Immer drafts cannot have computed properties". I believe this is due to data-binding modifying the state objects with getters/setters for observing the values. The error means that Immer cannot reliably clone the object because it contains functions/getters/setters/computed properties.

More information about this error can be found here: https://github.com/immerjs/immer/issues/392 https://github.com/immerjs/immer/issues/317 Possibly https://github.com/immerjs/immer/issues/202

You can see this error in action here (Click the button after the app loads): https://codesandbox.io/s/aurelia-javascript-sandbox-21zw1?file=/src/app.js

Expected/desired behavior: I spent a few hours researching and testing aurelia-store with Immer and aurelia-store, thinking I was doing something wrong. Eventually I gave up and asked about it in discord to find out it was a known issue.

IMO the documentation needs to be updated to remove mentioning Immer, or document an alternate approach that allows the use of Immer, such as not binding to the store state directly. Though I found even that can be tricky, as if you're not careful to properly copy your component state from the store state, aurelia still manages to bind into the store state and it's very difficult to track down where this is happening.

I also acknowledge I'm fairly new to Aurelia, so if I'm doing something wrong, please let me know.

NightWulfe commented 4 years ago

I just found reference to this same issue on Discourse, so I thought I'd link it here.

https://discourse.aurelia.io/t/aurelia-store-immerjs-and-objects/2601/30