Closed vivien-adnot-dr closed 3 years ago
Hello. Props are not deep cloned, that's by design. They are simply copied by reference.
If you want your array copied your might want to use "deepProps". https://stampit.js.org/api/deep-properties Anyhow. You've found the right "hack"! Initialising data in an initialiser is exactly the purpose of the initialisers. 😁
I welcome you to give more read to this page stampit.js.org
Cheers
Hello @koresar, many thanks for your fast answer :) Indeed, i didn't know about deepProps, it sounds like a very good tool. However in my usecase, it's probably not a good solution, because it concatenates arrays. And I don't want that, I just want my arrays 100% isolated from each other.
So, I will continue to use init() for my usecase and I will definitely keep in mind deepProps for the future !
Cheers
Hello, consider this code:
As you see in the code example, Stampit didn't clone the array when the second instance was created. Instead, it shared the reference from the first instance.
This is an unusual behaviour that should be fixed in my opinions.
PS: This little hack greens the test above:
rerun the unit test above, now it passes.