moy-dom
Version:
A flexiable Virtual DOM library for building modern web interface.
24 lines (19 loc) • 587 B
JavaScript
import dfsWalk from './dfsWalk'
export default function patch(node, patches){
const rootWithNullPatch = patches.rootWithNull
if(rootWithNullPatch){
const { type, vnode } = rootWithNullPatch
if(type === 4){
let newNode = Object.prototype.toString.call(vnode) === '[object Element]' ?
vnode.render() :
document.createTextNode(vnode)
node.appendChild(newNode)
}
if(type === 5){
node.removeChild(node.lastChild)
}
return
}
let walker = {index: 0}
dfsWalk(node.lastChild, walker, patches)
}