Closed shannonmoeller closed 8 years ago
I'm thinking this could be used for a quick comparison:
https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode
Hey @shannonmoeller, the recommended solution is to assign an id
attribute with a unique value for each <video>
element and morphdom
will match the elements up by the assigned ID.
If you don't like assigning an "id" attribute then you can provide your own getNodeKey(el)
function:
var morphedNode = morphdom(fromNode, toNode, {
getNodeKey: function(el) {
return el.id;
},
...
});
Let me know if that doesn't solve your problem.
Oh, awesome. I wasn't aware of that. Thanks!
This doesn't fully solve the issue. When an item is removed from the list, the other elements remain, so we're half way there. However, if an element is moved down the list, it's still getting overridden by the new element, even with the same id
.
It sounds like range.insertNode
(or insertBefore
) would do the trick. Instead of morphing, you would need to move the existing node to the new location in the DOM. @patrick-steele-idem does this sound correct?
Any way to detect the reorder of siblings? Perhaps optionally to avoid a performance penalty for this edge case. I have a list of videos. If video 2 is playing and video 1 is removed or reordered, video 2 is stopped because its source attribute is changes.