-
Notifications
You must be signed in to change notification settings - Fork 318
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
两颗树的最小距离 #5
Comments
@snowmagic1 对于列表的diff,virtual dom需要提供额外 var el1 = el('div', {'id': 'container'}, [el('ul'), el('li', {key: 'uid1'}, ['1'])])
var el2 = el('div', {'id': 'container'}, [el('ul'), el('li', {key: 'uid2'}, ['2']), el('li', {key: 'uid1'}, ['1'])])
var d = diff(el1, el2)
console.log(JSON.stringify(d)) 结果: {
"0":[
{
"type":1,
"moves":[
{
"index":1,
"item":{
"tagName":"li",
"props":{
"key":"uid2"
},
"children":[
"2"
],
"key":"uid2",
"count":1
},
"type":1
}
]
}
]
} 抱歉没有在文档中写清楚,后续加上。 |
ok, 我现在不太明白的地方是children reorder是做什么用的, 2种情况 所以reorder只有在children node里有key的情况下有用, 我这样理解对不对 BTW - 另外突然想起来call listdiff传了个'key'参数 |
@snowmagic1 对的,只有在有 因为在实际当中可能会对列表进行数据的新增、删除、排序。例如邮箱里面的收件箱列表,可以根据时间重新排序等等。如果没有这个 可以参考:https://github.com/livoras/simple-virtual-dom/blob/master/lib/diff.js#L24-L38 |
简单测试了一下,两颗树diff出来的结果不是最小距离 -
结果是两步
最小的距离应该是只有一步,插入一个li
The text was updated successfully, but these errors were encountered: