MCPcopy
hub / github.com/ygs-code/vue / patchVnode

Function patchVnode

vue.js:8672–8767  ·  view source on GitHub ↗
(
            oldVnode, // 旧的虚拟dom
            vnode,  // 新的虚拟dom
            insertedVnodeQueue,  // 删除虚拟dom队列
            removeOnly
        )

Source from the content-addressed store, hash-verified

8670
8671 // 对比 虚拟dom
8672 function patchVnode(
8673 oldVnode, // 旧的虚拟dom
8674 vnode, // 新的虚拟dom
8675 insertedVnodeQueue, // 删除虚拟dom队列
8676 removeOnly
8677 ) {
8678 if (oldVnode === vnode) { //如果他们相等
8679 return
8680 }
8681
8682 var elm = vnode.elm = oldVnode.elm; //获取真实的dom
8683
8684 // 判断是否有isAsyncPlaceholder 属性
8685 if (isTrue(oldVnode.isAsyncPlaceholder)) {
8686 //判断数据 是否不等于 undefined或者null
8687 if (isDef(vnode.asyncFactory.resolved)) {
8688 // ssr 渲染
8689 hydrate(oldVnode.elm, vnode, insertedVnodeQueue);
8690 } else {
8691 vnode.isAsyncPlaceholder = true;
8692 }
8693 return
8694 }
8695
8696 // reuse element for static trees.
8697 // note we only do this if the vnode is cloned -
8698 // if the new node is not cloned it means the render functions have been
8699 // reset by the hot-reload-api and we need to do a proper re-render.
8700 //为静态树重用元素。
8701 //注意,只有当vnode被克隆时,我们才这样做
8702 //如果新节点没有克隆,则表示渲染函数已经克隆
8703 //由hot-reload api重置,我们需要做一个适当的重新渲染。
8704 if (isTrue(vnode.isStatic) &&
8705 isTrue(oldVnode.isStatic) &&
8706 vnode.key === oldVnode.key &&
8707 (isTrue(vnode.isCloned) || isTrue(vnode.isOnce))
8708 ) {
8709 vnode.componentInstance = oldVnode.componentInstance;
8710 return
8711 }
8712
8713 var i;
8714 var data = vnode.data;
8715 // 钩子函数
8716 if (isDef(data) && isDef(i = data.hook) && isDef(i = i.prepatch)) {
8717 i(oldVnode, vnode);
8718 }
8719
8720 var oldCh = oldVnode.children;
8721 var ch = vnode.children;
8722 //循环组件实例 是否定义有 tag标签
8723 if (isDef(data) && isPatchable(vnode)) {
8724 // 触发钩子函数 更新钩子函数
8725 for (i = 0; i < cbs.update.length; ++i) {
8726 cbs.update[i](oldVnode, vnode);
8727 }
8728 // 触发钩子函数
8729 if (isDef(i = data.hook) && isDef(i = i.update)) {

Callers 2

updateChildrenFunction · 0.85
createPatchFunctionFunction · 0.85

Calls 8

isTrueFunction · 0.85
isDefFunction · 0.85
hydrateFunction · 0.85
isPatchableFunction · 0.85
isUndefFunction · 0.85
updateChildrenFunction · 0.85
addVnodesFunction · 0.85
removeVnodesFunction · 0.85

Tested by

no test coverage detected