Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array binding and observing #18

Open
Alexander-Taran opened this issue Mar 7, 2018 · 0 comments
Open

Array binding and observing #18

Alexander-Taran opened this issue Mar 7, 2018 · 0 comments
Labels
documentation help wanted Extra attention is needed

Comments

@Alexander-Taran
Copy link
Member

Alexander-Taran commented Mar 7, 2018

one of the biggest frustrations for developers is array binding and observing..
It all comes down to javascript

That should be covered in detail with examples

if you you want to ...
than you can..
the result will be..
side effects..

aurelia/binding#670

discussion from gitter:

mariaantony-gnanasekaran @mariaantony-gnanasekaran 10:27
Hi @Vheissu ,

We tried your suggestion. but unfortunately it doesn't work. firstNameChanged callback will be triggered only when we do assignment operation with array.

That's why we used collection observer to observe the array changes.

When we do push,pop, slice operation in our array dataSource, dataChanged callback function is getting triggered.

But when we change the array with index like the below code snippet

let arr = [ a:1];
arr.a =2;
dataChanged callback function is not getting trigger but view is getting updated.

Is there any way to observe the array changes, when we do array operation with index?

Alexander-Taran @Alexander-Taran 10:29
@mariaantony-gnanasekaran yeah use .splice () to replace the item
that will trigger array change handlers
.splice(i/ index of item to change /, 1 , newValue)

mariaantony-gnanasekaran @mariaantony-gnanasekaran 11:53
Hi @Alexander-Taran ,

Thanks for your suggestion.

I need to know is this an issue from Aurelia core? because whenever the property gets changed, we expect callback method to get triggered for notifying the change.

Alexander-Taran @Alexander-Taran 12:28
@mariaantony-gnanasekaran It is that it is not magic.. got the same thing with react.. atm
it all ties down to how objects are observed.
properties get converted to getters and setters.. and observing code is injected in to setters.. so whenever you assign something to a property - framework is notified..
for arrays there is another strategy.. I don't know the details but it somehow observes changes to array structure.. that's why splice works, but assigning by index does not..
because there is no way to covert indexer to getter setter.. I guess..
And what makes it confusing that in your view - it works.. because obervers are for properties of the objects in array..
We have to document it in understandable way..

But that is all how javascript works.. not specific to aurelia

@Alexander-Taran Alexander-Taran added help wanted Extra attention is needed documentation labels Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant