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

Sorting an array can result in an *Changed method firing #350

Closed
sorvell opened this issue Nov 18, 2013 · 2 comments
Closed

Sorting an array can result in an *Changed method firing #350

sorvell opened this issue Nov 18, 2013 · 2 comments
Assignees

Comments

@sorvell
Copy link
Contributor

sorvell commented Nov 18, 2013

If an element defines an array property foo and want to keep the array sorted, one might write code like this:

fooChanged: function() {
  this.foo.sort();
}

However, if the sort mutates the order of the array, the fooChanged method will be called again. This is because polymer reports array mutations as changes. This is appropriate for this use case. One probably wants to sort the array if it's new or if it mutates.

To fix this, we might consider adding a way to squelch changes.

@ghost ghost assigned sorvell Nov 18, 2013
@rafaelw
Copy link
Contributor

rafaelw commented Aug 14, 2014

This seems like an antipattern to me. If you mutate the data that you are observing in the callback which is called when it changes, you are going to have a bad time.

@sorvell
Copy link
Contributor Author

sorvell commented Aug 14, 2014

Agree, I kept it open because it was related to arrays.

This type of thing calls for a computed property and now that we have computed properties I think we can just close this.

@sorvell sorvell closed this as completed Aug 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants