I have a pretty basic custom element tri-playlist that I'm using to display a grid of another custom element tri-clip.
<dom-module id="tri-playlist">
<template>
<template is="dom-repeat" items={{clips}}>
<tri-clip clip-num={{item.clipNum}}></tri-clip>
</template>
</template>
</dom-module>
clips is generated dynamically by fetching information from a server. I'm notified of any changes to this information (even my own), and consequently update clips, after which the template takes care of updating the view to reflect the new data (a clip was deleted, order was changed, etc). Using jQuery UI Sortable, I can re-arrange clips in a playlist or drag them to a new one, and on sortstop I inform the server of any changes so that it stays in sync. That all seems to work fine, separately.
However, after the DOM has been manipulated by my jQuery sort, the template doesn't update correctly. From what I can tell, this is because the template isn't aware of those changes to its (local?/light?) DOM.
So for example, let's say I have three clips [A][B][C] in a playlist, and I move the first one so that it's now last [B][C][A]. When the server informs me of the change (my own) and I update clips accordingly, the template notices the shift and performs it a second time. In this example, the final outcome is [C][A][B].
So far the only way I can get it to work is by setting clips = []; before setting it correctly. Which results in any tri-clips on the screen to momentarily disappear, and forces Polymer to create the elements all over again, which defeats one of the advantages of using a Polymer template in the first place (TLDR: polymer data binding makes the smallest amount of changes necessary).
I've come across this:
When one of the template helper elements updates the DOM tree, it fires a dom-change event.
In most cases, you should interact with the created DOM by changing the model data, not by interacting directly with the created nodes. For those cases where you need to access the nodes directly, you can use the dom-change event.
but, I'm not really sure how to apply it to my situation. From what I understand, I would use the dom-change event if I wanted to do something with the nodes after the template triggered the changes. Or am I wrong about that? Is there anyway to inform the template that changes were made and it needs to update its model accordingly? Am I going about this the wrong way?
dom-repeatwas not designed to deal with it's dom being modified by something other than itself. Suggest you make an issue ticket here github.com/Polymer/polymer/issues. - Scott Miles