Data binding question

I have a general question about data binding… say we have a container with a data model, which gets its data assigned via an object in a variable called “blockData”. We have a property called “packages”, and we want to store the value of packages when our component is mounted in another property “oldPackages”. Here’s the code:

In our user flow, the user might change the value of “packages”. Before saving something to the database we want to know if “packages” is different from “oldPackages”. But it seems “oldPackages” is always updated when user changes the value of “packages”. Is this expected behavior? By assigning the value of “packages” to “oldPackages” when the component mounts, we are actually data binding the two properties together, so they are always the same? If so, is there a way to populate “oldPackages” with a value from “packages” that is not subject to change when “packages” changes?

Hello @Alex_Klein

Is this expected behavior?

That is how JS works. It passes objects using reference(here is underhood explanation Object references and copying)

If you want to create an independent copy of the object. You could use next blocks:

image

Regards, Dima.

Great solution, and perfect link to a great explanation about JS objects :green_heart: