Hi,
I’m using Aurelia since about 1 year on my free time, and I really love it. I’m mostly a backend developer (Python) but I’ve a small professional experience (1 year) with React/Redux.
Everything in Aurelia has been easy and pleasant to learn for me, except one point that I still struggle with : should I manage my data in a mutable or immutable style?
I understand the reactive binding as something like this: for example for an array, override the .push, .splice … to spy how the array is modifed and be able to update the DOM accordingly. So I would modify an array with mutation (.push, .slice…).
However, @computedFrom
seems to compare its argument based on immutability, ie for example when a array is reassigned: values = [...values, newValue]
instead of values.push(newValue)
.
I also browsed the Aurelia 2 documentation, and it didn’t make it clearer for me.
Here is an CodeSanbox example where an array of number is displayed, with its sum. With the immutable version, the sum is correctly displayed but it looses all the reactive binding advantage when displaying the array.
I know that they are workaround like incrementing a number after each array modification and doing something like @computeFrom(values, version)
, but I would expect a more direct solution.
In fact, I would have except everything working with mutable data, and @computeFrom
detects changes like reactive binding does (“syping” the .push
, .splice
etc), so the different framework parts would have been coherent.
Could you elaborate on what’s the opinion of Aurelia on the data mutability? I would love to see in the doc : By default with Aurelia, you must manage your data in a (im)mutable way, and as soon as the developer correctly manage the data, everything (the DOM, the computedFrom
) are correctly udpated.
Thanks is advance!