You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a node with a key which is re-used and re-ordered in the DOM when it is moved downwards, but not when it is moved upwards. Is there any reason for this?
Demo
Code
varh=require('virtual-dom/h');vardiff=require('virtual-dom/diff');varpatch=require('virtual-dom/patch');varcreateElement=require('virtual-dom/create-element');// 1: Create a function that declares what the DOM should look likefunctionrender(count){constx=[h('li',{key: 'foo'},h('input')),h('li',{key: 'bar'},h('input'))];constchildren=count%2===0 ? x : x.reverse();returnh('ul',children);}// 2: Initialise the documentvarcount=0;// We need some app data. Here we just store a count.vartree=render(count);// We need an initial treevarrootNode=createElement(tree);// Create an initial root DOM node ...document.body.appendChild(rootNode);// ... and it should be in the document// 3: Wire up the update logicsetInterval(function(){count++;varnewTree=render(count);varpatches=diff(tree,newTree);rootNode=patch(rootNode,patches);tree=newTree;},2000);
The text was updated successfully, but these errors were encountered:
I have a node with a key which is re-used and re-ordered in the DOM when it is moved downwards, but not when it is moved upwards. Is there any reason for this?
Demo
Code
The text was updated successfully, but these errors were encountered: