moy-dom
Version:
A flexiable Virtual DOM library for building modern web interface.
34 lines (28 loc) • 679 B
JavaScript
import dfsWalk from './dfsWalk'
export default function diff(newTree, oldTree){
const index = 0, patches = {}
if(oldTree === null){
if(newTree !== null){
patches.rootWithNull = {
type: 4, // append newNode
vnode: newTree,
}
}
return patches
}else{
if(newTree === null){
patches.rootWithNull = {
type: 5, // remove oldNode
}
return patches
}
}
if(Object.prototype.toString.call(newTree) !== '[object Element]'){
newTree += ''
}
if(Object.prototype.toString.call(oldTree) !== '[object Element]'){
oldTree += ''
}
dfsWalk(newTree, oldTree, index, patches)
return patches
}