How to distinguish between structural changes to array made in parent element vs property changes to an item of array made in child element observer?

21 views
Skip to first unread message

Santanu Basu

unread,
Mar 4, 2017, 11:34:31 PM3/4/17
to Polymer
I have posted this in another form on SO (http://stackoverflow.com/questions/42565640/how-to-distinguish-between-structural-changes-to-array-made-in-parent-element-vs) and in the 2.0-preview branch slack channel, but I know they are heads down with the upcoming release, so hopefully somewhere in the broader group here will have insight to share.

The TL;DR question: how many times should the observer, defined in editor-element.html log to console for the following sample code: https://plnkr.co/edit/iTZqM4GwpASEqQgtRGEk?  I would have expected 4, but it actually happens 6 times.

More details: the elements are a list element which, using dom-repeat, renders a list of todos, and each todo is rendered by an instance of an editor element.  The data is a list of todo objects, each of which has a primitive property called description.  First, two todo objects are pushed onto the list.  Then the first todo object's description property is edited.  Then a third todo object is unshifted (not pushed) onto the list.  The data binding is defined two way between the items inside the dom-repeat of the list element and the todo property of the editor element.  In other words, the binding is made at the object, not the property.  The editor element defines an observer on "todo.description", printing a message to the console each time an observation is made.

thanks in advance for any help

Karl Tiedt

unread,
Mar 5, 2017, 12:42:08 AM3/5/17
to Santanu Basu, Polymer
Not sure if it is the intended behavior or not, but I wouldn't find it hard to believe that the change observer fires since the index of each element changes as you unshift into the list array...

essentially: list[0] becomes list[1] meaning previous[1] != list[1] effectively causing a series of changes for each list item...

Again, cant attest to it being expected or not, but I would not be surprised by your log output at all right this second.

-Karl Tiedt

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/94aba116-6925-4ea6-880d-b2e6ca7b5e7d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Santanu Basu

unread,
Mar 5, 2017, 1:55:38 AM3/5/17
to Polymer
I could also see the log output being reasonable.  But that gets at the question behind the question, which is this:  How can I observe a change caused by an actual edit of an item of the list, and not a reassignment of the data objects to the element instances that is causes by things like unshift, sort, or filter?  That distinction is really what I'm interested in.
Reply all
Reply to author
Forward
0 new messages