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

this.push doesn't notify changes to computed property #2644

Closed
arthurgubaidullin opened this issue Oct 29, 2015 · 10 comments
Closed

this.push doesn't notify changes to computed property #2644

arthurgubaidullin opened this issue Oct 29, 2015 · 10 comments

Comments

@arthurgubaidullin
Copy link

I have array property and computed property that depend on array. When i use this.push() method, my computed property doesn't recompute.

@ebidel
Copy link
Contributor

ebidel commented Oct 29, 2015

Please include a jsbin that repos the issue.

@chiefcll
Copy link

We're seeing something similar... We think its related to #2007 - The changes now send notification changes of array.#1.prop rather than array.1.prop - so if you set up any observer on that property without the # it won't get called.

@samccone
Copy link
Contributor

I think this is also related
#2556

@chiefcll
Copy link

@ebidel
Copy link
Contributor

ebidel commented Oct 29, 2015

Using https://rawgit.com/Polymer/polymer/v1.1.5/polymer.html in that demo, I see two console logs
Using https://rawgit.com/Polymer/polymer/v1.2.0/polymer.html, I see one :(

This is a regression.

@ebidel
Copy link
Contributor

ebidel commented Oct 29, 2015

So I'm told from @kevinpschaaf this was never supposed to work. It's even documented as such: https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#array-binding.

binding to or observing array indices is not supported. i.e. observer: [ 'myArrayChanged(myArray.1.value)' ] and {{myArray.1.value}}

that was never intended to be supported, so the fact that it changed is a result of relying on an unsupported feature

reason is that all path notifications for arrays are done as keys; observing an index (i.e. as an observer dep or binding) would require reverse lookup from key back to index, which is an O(n) operation for each

@ebidel ebidel removed the regression label Oct 29, 2015
@ebidel
Copy link
Contributor

ebidel commented Oct 29, 2015

Closing as per the observation in the previous comment.

@ebidel ebidel closed this as completed Oct 29, 2015
@arthurgubaidullin
Copy link
Author

@kevinpschaaf
Copy link
Member

@lapteuh computeMyComputedArray(myArray) only re-computes when the myArray reference itself changes. To re-compute on any deep change to myArray, use computeMyComputedArray(myArray.*):

http://plnkr.co/edit/348Amty1bSJMEZX5g4dy?p=preview

@arthurgubaidullin
Copy link
Author

@kevinpschaaf thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants