How to use removeVnodes method in Playwright Internal

Best JavaScript code snippet using playwright-internal

vueInner.js

Source:vueInner.js Github

copy

Full Screen

...249}250/**251 * removeVnodes 会批量调用removeNode移除节点252 */253function removeVnodes(parentElm, vnodes, startIdx, endIdx) {254 for (; startIdx <= endIdx; ++startIdx) {255 const ch = vnodes[startIdx];256 if (ch) {257 removeNode(ch.elm);258 }259 }260}261// patch(打补丁)262// patch的核心diff算法,我们用diff算法对比出两棵树的差异263// diff算法是通过同层的树节点进行比较而非对树进行逐层搜索遍历的方式,所以时间复杂度只有264// O(n),是一种相当高效的算法265function patch (oldVnode, vnode, parentElm) {266 if (!oldVnode) {267 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);268 } else if (!vnode) {269 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1)270 } else {271 if (sameVnode(oldVNode, vnode)) {272 patchVnode(oldVNode, vnode);273 } else {274 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);275 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);276 }277 }278}279/**** 第七章 批量异步更新策略及nextTick原理 *****/...

Full Screen

Full Screen

2.diff.js

Source:2.diff.js Github

copy

Full Screen

...52 nodeOps.removeChild(parent, el);53 }54}55// removeVnodes 会批量调用 removeNode 移除节点。56function removeVnodes(parentElm, vnodes, startIdx, endIdx) {57 for (; startIdx <= endIdx; ++startIdx) {58 const ch = vnodes[startIdx];59 if (ch) {60 removeNode(ch.elm);61 }62 }63}64// diff 算法是通过同层的树节点进行比较而非对树进行逐层搜索遍历的方式65// 所以时间复杂度只有 O(n),是一种相当高效的算法66function patch(oldVnode, vnode, parentElm) {67 if (!oldVnode) {68 // 没有老节点,插入新节点69 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);70 } else if (!vnode) {71 // 没有新节点,删除老节点72 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);73 } else {74 // 如果是同一个节点,patchVnode75 if (sameVnode(oldVNode, vnode)) {76 patchVnode(oldVNode, vnode);77 } else {78 // 不是一个节点,删除老节点,新增新节点79 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);80 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);81 }82 }83}84// 什么情况下两个 VNode 会属于 sameVnode (相同的节点)呢?85function sameVnode() {86 return (87 a.key === b.key &&88 a.tag === b.tag &&89 a.isComment === b.isComment &&90 !!a.data === !!b.data &&91 sameInputType(a, b)92 );93}94function sameInputType(a, b) {95 if (a.tag !== "input") return true;96 let i;97 const typeA = (i = a.data) && (i = i.attrs) && i.type;98 const typeB = (i = b.data) && (i = i.attrs) && i.type;99 return typeA === typeB;100}101/**102 * 核心方法103 * @param {*} oldVnode104 * @param {*} vnode105 * @returns106 */107function patchVnode(oldVnode, vnode) {108 // 新老 VNode 节点相同的情况下,就不需要做任何改变了,直接 return 掉109 if (oldVnode === vnode) {110 return;111 }112 // 在当新老 VNode 节点都是 isStatic(静态的),并且 key 相同时,113 // 只要将 componentInstance 与 elm 从老 VNode 节点“拿过来”即可。114 // 这里的 isStatic 也就是前面提到过的「编译」的时候会将静态节点标记出来,这样就可以跳过比对的过程。115 if (vnode.isStatic && oldVnode.isStatic && vnode.key === oldVnode.key) {116 vnode.elm = oldVnode.elm;117 vnode.componentInstance = oldVnode.componentInstance;118 return;119 }120 const elm = (vnode.elm = oldVnode.elm);121 const oldCh = oldVnode.children;122 const ch = vnode.children;123 // 当新 VNode 节点是文本节点的时候,直接用 setTextContent 来设置 text124 if (vnode.text) {125 nodeOps.setTextContent(elm, vnode.text);126 } else {127 // oldCh 与 ch 都存在且不相同时,使用 updateChildren 函数来更新子节点128 if (oldCh && ch && oldCh !== ch) {129 updateChildren(elm, oldCh, ch);130 } else if (ch) {131 // 如果只有 ch 存在的时候132 // 如果老节点是文本节点则先将节点的文本清除133 if (oldVnode.text) nodeOps.setTextContent(elm, "");134 // 然后将 ch 批量插入到节点elm下。135 addVnodes(elm, null, ch, 0, ch.length - 1);136 } else if (oldCh) {137 // 同理当只有 oldch 存在时,说明需要将老节点通过 removeVnodes 全部清除138 removeVnodes(elm, oldCh, 0, oldCh.length - 1);139 } else if (oldVnode.text) {140 // 最后一种情况是当只有老节点是文本节点的时候,清除其节点文本内容。141 nodeOps.setTextContent(elm, "");142 }143 }144}145function updateChildren(parentElm, oldCh, newCh) {146 let oldStartIdx = 0;147 let newStartIdx = 0;148 let oldEndIdx = oldCh.length - 1;149 let oldStartVnode = oldCh[0];150 let oldEndVnode = oldCh[oldEndIdx];151 let newEndIdx = newCh.length - 1;152 let newStartVnode = newCh[0];153 let newEndVnode = newCh[newEndIdx];154 let oldKeyToIdx, idxInOld, elmToMove, refElm;155 // while 循环,在这过程中,oldStartIdx、newStartIdx、oldEndIdx 以及 newEndIdx 会逐渐向中间靠拢156 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {157 if (!oldStartVnode) {158 oldStartVnode = oldCh[++oldStartIdx];159 } else if (!oldEndVnode) {160 oldEndVnode = oldCh[--oldEndIdx];161 } else if (sameVnode(oldStartVnode, newStartVnode)) {162 patchVnode(oldStartVnode, newStartVnode);163 oldStartVnode = oldCh[++oldStartIdx];164 newStartVnode = newCh[++newStartIdx];165 } else if (sameVnode(oldEndVnode, newEndVnode)) {166 patchVnode(oldEndVnode, newEndVnode);167 oldEndVnode = oldCh[--oldEndIdx];168 newEndVnode = newCh[--newEndIdx];169 } else if (sameVnode(oldStartVnode, newEndVnode)) {170 patchVnode(oldStartVnode, newEndVnode);171 nodeOps.insertBefore(172 parentElm,173 oldStartVnode.elm,174 nodeOps.nextSibling(oldEndVnode.elm)175 );176 oldStartVnode = oldCh[++oldStartIdx];177 newEndVnode = newCh[--newEndIdx];178 } else if (sameVnode(oldEndVnode, newStartVnode)) {179 patchVnode(oldEndVnode, newStartVnode);180 nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);181 oldEndVnode = oldCh[--oldEndIdx];182 newStartVnode = newCh[++newStartIdx];183 } else {184 let elmToMove = oldCh[idxInOld];185 if (!oldKeyToIdx)186 oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);187 idxInOld = newStartVnode.key ? oldKeyToIdx[newStartVnode.key] : null;188 // 当前newStartVnode在old还未遍历完的项目中,是否存在189 if (!idxInOld) {190 createElm(newStartVnode, parentElm);191 newStartVnode = newCh[++newStartIdx];192 } else {193 elmToMove = oldCh[idxInOld];194 if (sameVnode(elmToMove, newStartVnode)) {195 patchVnode(elmToMove, newStartVnode);196 oldCh[idxInOld] = undefined;197 nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm);198 newStartVnode = newCh[++newStartIdx];199 } else {200 createElm(newStartVnode, parentElm);201 newStartVnode = newCh[++newStartIdx];202 }203 }204 }205 }206 // 当 while 循环结束以后,如果 oldStartIdx > oldEndIdx,说明老节点比对完了207 // 但是新节点还有多的,需要将新节点插入到真实 DOM 中去,调用 addVnodes 将这些节点插入即可208 if (oldStartIdx > oldEndIdx) {209 refElm = newCh[newEndIdx + 1] ? newCh[newEndIdx + 1].elm : null;210 addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx);211 } else if (newStartIdx > newEndIdx) {212 // 如果满足 newStartIdx > newEndIdx 条件,说明新节点比对完了,老节点还有多213 // 将这些无用的老节点通过 removeVnodes 批量删除即可。214 removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);215 }216}217function createKeyToOldIdx(children, beginIdx, endIdx) {218 let i, key;219 const map = {};220 for (i = beginIdx; i <= endIdx; ++i) {221 key = children[i].key;222 if (isDef(key)) map[key] = i;223 }224 return map;...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...3 // 不存在旧的node,将新的node直接插入父节点4 if (!oldVnode) {5 addVnodes(parentElm, null, vnode, 0, vnode.length - 1)6 } else if (!vnode) { // 不存在新的node,移除就的节点7 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1)8 } else {9 // 存在切相同 10 if (sameVnode(oldVNode, vnode)) {11 patchVnode(oldVNode, vnode)12 } else {13 // 存在不同,将新节点替换久节点14 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1)15 addVnodes(parentElm, null, vnode, 0, vnode.length - 1)16 }17 }18}19// 相同节点的比较20function patchVnode(oldVnode, vnode) {21 // 完成相同,直接返回22 if (oldVnode === vnode) {23 return24 }25 // 静态的节点,直接替换26 if (vnode.isStatic && oldVnode.isStatic && vnode.key === oldVnode.key) {27 vnode.elm = oldVnode.elm28 vnode.componentInstance = oldVnode.componentInstance29 return30 }31 // 判断子节点32 const elm = vnode.elm = oldVnode.elm33 const oldCh = oldVnode.children34 const ch = vnode.children35 // 是文本节点,直接替换36 if (vnode.text) {37 nodeOps.setTextContent(elm, vnode.text)38 } else {39 if (oldCh && ch) { //同时存在40 if (oldCh !== ch) { // 不相同,更新子节点41 updateChildren(elm, oldCh, ch)42 }43 } else if (ch) { 44 if (oldVnode.text) nodeOps.setTextContent(elm, '')45 addVnodes(elm, null, ch, 0, ch.length - 1)46 } else if (oldCh) {47 removeVnodes(elm, oldCh, 0, oldCh.length - 1)48 } else if (oldVnode.text) {49 nodeOps.setTextContent(elm, '')50 }51 }52}53// 判断input的类型54function sameInputType(a, b) {55 if (a.tag !== 'input') return true56 let i57 const typeA = (i = a.data) && (i = i.attrs) && i.type58 const typeB = (i = b.data) && (i = i.attrs) && i.type59 return typeA === typeB60}61// 判断相同的node62function sameVnode() {63 return (64 a.key === b.key &&65 a.tag === b.tag &&66 a.isComment === b.isComment &&67 !!a.data === !!b.data &&68 sameInputType(a, b)69 )70}71// 将el插入到parent中72function insert(parent, elm, ref) {73 if (parent) {74 // 如果是ref 75 if (ref) {76 if (ref.parentNode === parent) {77 nodeOps.insertBefore(parent, elm, ref)78 }79 } else {80 nodeOps.appendChild(parent, elm)81 }82 }83}84// 创建元素85function createElm(vnode, parentElm, refElm) {86 if (vnode.tag) {87 insert(parentElm, nodeOps.createElement(vnode.tag), refElm)88 } else {89 insert(parentElm, nodeOps.createTextNode(vnode.text), refElm)90 }91}92// 批量添加node93function addVnodes(parentElm, refElm, vnodes, startIdx, endIdx) {94 for (; startIdx <= endIdx; ++startIdx) {95 createElm(vnodes[startIdx], parentElm, refElm)96 }97}98// 移除node99function removeNode(el) {100 const parent = nodeOps.parentNode(el)101 if (parent) {102 nodeOps.removeChild(parent, el)103 }104}105// 批量移除node106function removeVnodes(parentElm, vnodes, startIdx, endIdx) {107 for (; startIdx <= endIdx; ++startIdx) {108 const ch = vnodes[startIdx]109 if (ch) {110 removeNode(ch.elm)111 }112 }113}114// 将key map 转变成数组115function createKeyToOldIdx(children, beginIdx, endIdx) {116 let i, key117 const map = {}118 for (i = beginIdx; i <= endIdx; ++i) {119 key = children[i].key120 if (isDef(key)) map[key] = i121 }122 return map123}124// 更新子节点125function updateChildren(parentElm, oldCh, newCh) {126 let oldStartIdx = 0 // 旧节点开始127 let newStartIdx = 0 // 128 let oldEndIdx = oldCh.length - 1129 let oldStartVnode = oldCh[0]130 let oldEndVnode = oldCh[oldEndIdx] // 旧节点的node, 与index同步131 let newEndIdx = newCh.length - 1132 let newStartVnode = newCh[0]133 let newEndVnode = newCh[newEndIdx]134 let oldKeyToIdx, idxInOld, elmToMove, refElm135 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {136 // 旧节点不存在,直接替换137 if (!oldStartVnode) {138 oldStartVnode = oldCh[++oldStartIdx]139 } else if (!oldEndVnode) {140 oldEndVnode = oldCh[--oldEndIdx]141 } else if (sameVnode(oldStartVnode, newStartVnode)) { // 新旧相同的四种情况142 patchVnode(oldStartVnode, newStartVnode)143 oldStartVnode = oldCh[++oldStartIdx]144 newStartVnode = newCh[++newStartIdx]145 } else if (sameVnode(oldEndVnode, newEndVnode)) {146 patchVnode(oldEndVnode, newEndVnode)147 oldEndVnode = oldCh[--oldEndIdx]148 newEndVnode = newCh[--newEndIdx]149 } else if (sameVnode(oldStartVnode, newEndVnode)) {150 patchVnode(oldStartVnode, newEndVnode)151 nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm))152 oldStartVnode = oldCh[++oldStartIdx]153 newEndVnode = newCh[--newEndIdx]154 } else if (sameVnode(oldEndVnode, newStartVnode)) {155 patchVnode(oldEndVnode, newStartVnode)156 nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm)157 oldEndVnode = oldCh[--oldEndIdx]158 newStartVnode = newCh[++newStartIdx]159 } else { //新旧不相同160 let elmToMove = oldCh[idxInOld]161 if (!oldKeyToIdx) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx) // 把旧节点的key转成数组,方便查找162 idxInOld = newStartVnode.key ? oldKeyToIdx[newStartVnode.key] : null 163 if (!idxInOld) { // 存在和新node相同的key164 createElm(newStartVnode, parentElm)165 newStartVnode = newCh[++newStartIdx]166 } else {167 elmToMove = oldCh[idxInOld]168 if (sameVnode(elmToMove, newStartVnode)) { // 完全相同,直接替换169 patchVnode(elmToMove, newStartVnode)170 oldCh[idxInOld] = undefined // 防止重复171 nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm)172 newStartVnode = newCh[++newStartIdx]173 } else { //不相同,创建新node, 插入174 createElm(newStartVnode, parentElm)175 newStartVnode = newCh[++newStartIdx]176 }177 }178 }179 }180 if (oldStartIdx > oldEndIdx) { // 新node多,直接插入181 refElm = (newCh[newEndIdx + 1]) ? newCh[newEndIdx + 1].elm : null182 addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx)183 } else if (newStartIdx > newEndIdx) { // 旧node多直接删除184 removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx)185 }186}187// 封装多平台node api188const nodeOps = {189 // 文本节点设置文本190 setTextContent() {191 },192 parentNode() {193 },194 removeChild() {195 },196 nextSibling() {197 },198 insertBefore() {...

Full Screen

Full Screen

2018-10-30-vue-diff.js

Source:2018-10-30-vue-diff.js Github

copy

Full Screen

1function patch (oldVNode, vnode, parentElm) {2 if (!oldVnode) {3 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);4 } else if (!vnode) {5 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);6 } else {7 if (sameVnode(oldVNode, vnode)) {8 patchVnode(oldVNode, vnode);9 } else {10 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);11 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);12 }13 }14}15function patchVnode (oldVnode, vnode) {16 if (oldVnode === vnode) {17 return;18 }19 if (vnode.isStatic && oldVnode.isStatic && vnode.key === oldVnode.key) {20 vnode.elm = oldVnode.elm;21 vnode.componentInstance = oldVnode.componentInstance;22 return;23 }24 const elm = vnode.elm = oldVnode.elm;25 const oldCh = oldVnode.children;26 const ch = vnode.children;27 if (vnode.text) {28 nodeOps.setTextContent(elm, vnode.text);29 } else {30 if (oldCh && ch && (oldCh !== ch)) {31 updateChildren(elm, oldCh, ch);32 } else if (ch) {33 if (oldVnode.text) nodeOps.setTextContent(elm, '');34 addVnodes(elm, null, ch, 0, ch.length - 1);35 } else if (oldCh) {36 removeVnodes(elm, oldCh, 0, oldCh.length - 1)37 } else if (oldVnode.text) {38 nodeOps.setTextContent(elm, '')39 }40 }41}42function sameInputType (a, b) {43 if (a.tag !== 'input') return true44 let i45 const typeA = (i = a.data) && (i = i.attrs) && i.type46 const typeB = (i = b.data) && (i = i.attrs) && i.type47 return typeA === typeB48}49function sameVnode () {50 return (51 a.key === b.key &&52 a.tag === b.tag &&53 a.isComment === b.isComment &&54 !!a.data === !!b.data &&55 sameInputType(a, b)56 )57}58function insert (parent, elm, ref) {59 if (parent) {60 if (ref) {61 if (ref.parentNode === parent) {62 nodeOps.insertBefore(parent, elm, ref);63 }64 } else {65 nodeOps.appendChild(parent, elm)66 }67 }68}69function createElm (vnode, parentElm, refElm) {70 if (vnode.tag) {71 insert(parentElm, nodeOps.createElement(vnode.tag), refElm);72 } else {73 insert(parentElm, nodeOps.createTextNode(vnode.text), refElm);74 }75}76function addVnodes (parentElm, refElm, vnodes, startIdx, endIdx) {77 for (; startIdx <= endIdx; ++startIdx) {78 createElm(vnodes[startIdx], parentElm, refElm);79 }80}81function removeNode (el) {82 const parent = nodeOps.parentNode(el);83 if (parent) {84 nodeOps.removeChild(parent, el);85 }86}87function removeVnodes (parentElm, vnodes, startIdx, endIdx) {88 for (; startIdx <= endIdx; ++startIdx) {89 const ch = vnodes[startIdx]90 if (ch) {91 removeNode(ch.elm);92 }93 }94}95function createKeyToOldIdx (children, beginIdx, endIdx) {96 let i, key97 const map = {}98 for (i = beginIdx; i <= endIdx; ++i) {99 key = children[i].key100 if (isDef(key)) map[key] = i101 }102 return map103}104function updateChildren (parentElm, oldCh, newCh) {105 let oldStartIdx = 0;106 let newStartIdx = 0;107 let oldEndIdx = oldCh.length - 1;108 let oldStartVnode = oldCh[0];109 let oldEndVnode = oldCh[oldEndIdx];110 let newEndIdx = newCh.length - 1;111 let newStartVnode = newCh[0];112 let newEndVnode = newCh[newEndIdx];113 114 let oldKeyToIdx, idxInOld, elmToMove, refElm;115 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {116 if (!oldStartVnode) {117 oldStartVnode = oldCh[++oldStartIdx];118 } else if (!oldEndVnode) {119 oldEndVnode = oldCh[--oldEndIdx];120 } else if (sameVnode(oldStartVnode, newStartVnode)) {121 patchVnode(oldStartVnode, newStartVnode);122 oldStartVnode = oldCh[++oldStartIdx];123 newStartVnode = newCh[++newStartIdx];124 } else if (sameVnode(oldEndVnode, newEndVnode)) {125 patchVnode(oldEndVnode, newEndVnode);126 oldEndVnode = oldCh[--oldEndIdx];127 newEndVnode = newCh[--newEndIdx];128 } else if (sameVnode(oldStartVnode, newEndVnode)) {129 patchVnode(oldStartVnode, newEndVnode);130 nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm));131 oldStartVnode = oldCh[++oldStartIdx];132 newEndVnode = newCh[--newEndIdx];133 } else if (sameVnode(oldEndVnode, newStartVnode)) {134 patchVnode(oldEndVnode, newStartVnode);135 nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);136 oldEndVnode = oldCh[--oldEndIdx];137 newStartVnode = newCh[++newStartIdx];138 } else {139 let elmToMove = oldCh[idxInOld];140 if (!oldKeyToIdx) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);141 idxInOld = newStartVnode.key ? oldKeyToIdx[newStartVnode.key] : null;142 if (!idxInOld) {143 createElm(newStartVnode, parentElm);144 newStartVnode = newCh[++newStartIdx];145 } else {146 elmToMove = oldCh[idxInOld];147 if (sameVnode(elmToMove, newStartVnode)) {148 patchVnode(elmToMove, newStartVnode);149 oldCh[idxInOld] = undefined;150 nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm);151 newStartVnode = newCh[++newStartIdx];152 } else {153 createElm(newStartVnode, parentElm);154 newStartVnode = newCh[++newStartIdx];155 }156 }157 }158 }159 if (oldStartIdx > oldEndIdx) {160 refElm = (newCh[newEndIdx + 1]) ? newCh[newEndIdx + 1].elm : null;161 addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx);162 } else if (newStartIdx > newEndIdx) {163 removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);164 }165}166const nodeOps = {167 setTextContent () {168 169 },170 parentNode () {171 },172 removeChild () {173 },174 nextSibling () {175 },176 insertBefore () {177 ...

Full Screen

Full Screen

《数据状态更新时的差异 diff 及 patch 机制》.js

Source:《数据状态更新时的差异 diff 及 patch 机制》.js Github

copy

Full Screen

1function patch(oldVNode, vnode, parentElm) {2 if (!oldVnode) {3 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);4 } else if (!vnode) {5 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);6 } else {7 if (sameVnode(oldVNode, vnode)) {8 patchVnode(oldVNode, vnode);9 } else {10 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);11 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);12 }13 }14}15function patchVnode(oldVnode, vnode) {16 if (oldVnode === vnode) {17 return;18 }19 if (vnode.isStatic && oldVnode.isStatic && vnode.key === oldVnode.key) {20 vnode.elm = oldVnode.elm;21 vnode.componentInstance = oldVnode.componentInstance;22 return;23 }24 const elm = vnode.elm = oldVnode.elm;25 const oldCh = oldVnode.children;26 const ch = vnode.children;27 if (vnode.text) {28 nodeOps.setTextContent(elm, vnode.text);29 } else {30 if (oldCh && ch && (oldCh !== ch)) {31 updateChildren(elm, oldCh, ch);32 } else if (ch) {33 if (oldVnode.text) nodeOps.setTextContent(elm, '');34 addVnodes(elm, null, ch, 0, ch.length - 1);35 } else if (oldCh) {36 removeVnodes(elm, oldCh, 0, oldCh.length - 1)37 } else if (oldVnode.text) {38 nodeOps.setTextContent(elm, '')39 }40 }41}42function sameInputType(a, b) {43 if (a.tag !== 'input') return true44 let i45 const typeA = (i = a.data) && (i = i.attrs) && i.type46 const typeB = (i = b.data) && (i = i.attrs) && i.type47 return typeA === typeB48}49function sameVnode() {50 return (51 a.key === b.key &&52 a.tag === b.tag &&53 a.isComment === b.isComment &&54 !!a.data === !!b.data &&55 sameInputType(a, b)56 )57}58function insert(parent, elm, ref) {59 if (parent) {60 if (ref) {61 if (ref.parentNode === parent) {62 nodeOps.insertBefore(parent, elm, ref);63 }64 } else {65 nodeOps.appendChild(parent, elm)66 }67 }68}69function createElm(vnode, parentElm, refElm) {70 if (vnode.tag) {71 insert(parentElm, nodeOps.createElement(vnode.tag), refElm);72 } else {73 insert(parentElm, nodeOps.createTextNode(vnode.text), refElm);74 }75}76function addVnodes(parentElm, refElm, vnodes, startIdx, endIdx) {77 for (; startIdx <= endIdx; ++startIdx) {78 createElm(vnodes[startIdx], parentElm, refElm);79 }80}81function removeNode(el) {82 const parent = nodeOps.parentNode(el);83 if (parent) {84 nodeOps.removeChild(parent, el);85 }86}87function removeVnodes(parentElm, vnodes, startIdx, endIdx) {88 for (; startIdx <= endIdx; ++startIdx) {89 const ch = vnodes[startIdx]90 if (ch) {91 removeNode(ch.elm);92 }93 }94}95function createKeyToOldIdx(children, beginIdx, endIdx) {96 let i, key97 const map = {}98 for (i = beginIdx; i <= endIdx; ++i) {99 key = children[i].key100 if (isDef(key)) map[key] = i101 }102 return map103}104function updateChildren(parentElm, oldCh, newCh) {105 let oldStartIdx = 0;106 let newStartIdx = 0;107 let oldEndIdx = oldCh.length - 1;108 let oldStartVnode = oldCh[0];109 let oldEndVnode = oldCh[oldEndIdx];110 let newEndIdx = newCh.length - 1;111 let newStartVnode = newCh[0];112 let newEndVnode = newCh[newEndIdx];113 let oldKeyToIdx, idxInOld, elmToMove, refElm;114 while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {115 if (!oldStartVnode) {116 oldStartVnode = oldCh[++oldStartIdx];117 } else if (!oldEndVnode) {118 oldEndVnode = oldCh[--oldEndIdx];119 } else if (sameVnode(oldStartVnode, newStartVnode)) {120 patchVnode(oldStartVnode, newStartVnode);121 oldStartVnode = oldCh[++oldStartIdx];122 newStartVnode = newCh[++newStartIdx];123 } else if (sameVnode(oldEndVnode, newEndVnode)) {124 patchVnode(oldEndVnode, newEndVnode);125 oldEndVnode = oldCh[--oldEndIdx];126 newEndVnode = newCh[--newEndIdx];127 } else if (sameVnode(oldStartVnode, newEndVnode)) {128 patchVnode(oldStartVnode, newEndVnode);129 nodeOps.insertBefore(parentElm, oldStartVnode.elm, nodeOps.nextSibling(oldEndVnode.elm));130 oldStartVnode = oldCh[++oldStartIdx];131 newEndVnode = newCh[--newEndIdx];132 } else if (sameVnode(oldEndVnode, newStartVnode)) {133 patchVnode(oldEndVnode, newStartVnode);134 nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);135 oldEndVnode = oldCh[--oldEndIdx];136 newStartVnode = newCh[++newStartIdx];137 } else {138 let elmToMove = oldCh[idxInOld];139 if (!oldKeyToIdx) oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx);140 idxInOld = newStartVnode.key ? oldKeyToIdx[newStartVnode.key] : null;141 if (!idxInOld) {142 createElm(newStartVnode, parentElm);143 newStartVnode = newCh[++newStartIdx];144 } else {145 elmToMove = oldCh[idxInOld];146 if (sameVnode(elmToMove, newStartVnode)) {147 patchVnode(elmToMove, newStartVnode);148 oldCh[idxInOld] = undefined;149 nodeOps.insertBefore(parentElm, newStartVnode.elm, oldStartVnode.elm);150 newStartVnode = newCh[++newStartIdx];151 } else {152 createElm(newStartVnode, parentElm);153 newStartVnode = newCh[++newStartIdx];154 }155 }156 }157 }158 if (oldStartIdx > oldEndIdx) {159 refElm = (newCh[newEndIdx + 1]) ? newCh[newEndIdx + 1].elm : null;160 addVnodes(parentElm, refElm, newCh, newStartIdx, newEndIdx);161 } else if (newStartIdx > newEndIdx) {162 removeVnodes(parentElm, oldCh, oldStartIdx, oldEndIdx);163 }164}165const nodeOps = {166 setTextContent() {167 },168 parentNode() {169 },170 removeChild() {171 },172 nextSibling() {173 },174 insertBefore() {175 }176}

Full Screen

Full Screen

vapi.js

Source:vapi.js Github

copy

Full Screen

...59function patch(oldVnode, vnode, parentElm) {60 if (!oldVnode) {61 addVnodes(parentElm, null, vnode, 0, vnode.length - 1)62 } else if (!vnode) {63 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1)64 } else {65 if (sameVnode(oldVnode, vnode)) {66 patchVnode(oldVnode, vnode)67 } else {68 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1)69 addVnodes(parentElm, null, vnode, 0, vnode.length - 1)70 }71 }72}73function sameVnode(a, b) {74 return (75 a.key === b.key &&76 a.tag === b.tag &&77 a.isComment === b.isComment &&78 (!!a.data) === (!!b.data) &&79 sameInputType(a, b)80 )81}82function sameInputType(a, b) {83 if (a.tag !== 'input') return true84 let i85 const typeA = (i = a.data) && (i = i.attrs) && i.type86 const typeB = (i = b.data) && (i = i.attrs) && i.type87 return typeA === typeB88}89function patchVnode(oldVnode, vnode) {90 if (oldVnode === vnode) {91 return92 }93 if (vnode.isStatic && oldVnode.isStatic && vnode.key === oldVnode.key) {94 vnode.elm = oldVnode.elm;95 vnode.componentInstance = oldVnode.componentInstance;96 return;97 }98 const elm = vnode.elm = oldVnode.elm;99 const oldCh = oldVnode.children;100 const ch = vnode.children;101 if (vnode.text) {102 nodeOps.setTextContent(elm, vnode.text);103 } else {104 if (oldCh && ch && (oldCh !== ch)) {105 updateChildren(elm, oldCh, ch);106 } else if (ch) {107 if (oldVnode.text) nodeOps.setTextContent(elm, '');108 addVnodes(elm, null, ch, 0, ch.length - 1);109 } else if (oldCh) {110 removeVnodes(elm, oldCh, 0, oldCh.length - 1)111 } else if (oldVnode.text) {112 nodeOps.setTextContent(elm, '')113 }114 }...

Full Screen

Full Screen

patch.js

Source:patch.js Github

copy

Full Screen

...4function patch (oldVnode, vnode, parentElm) {5 if (!oldVnode) {6 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);7 } else if (!vnode) {8 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);9 } else {10 if (sameVnode(oldVNode, vnode)) {11 patchVnode(oldVNode, vnode);12 } else {13 removeVnodes(parentElm, oldVnode, 0, oldVnode.length - 1);14 addVnodes(parentElm, null, vnode, 0, vnode.length - 1);15 }16 }17}18function addVnodes (parentElm, refElm, vnodes, startIdx, endIdx) {19 for (; startIdx <= endIdx; ++startIdx) {20 createElm(vnodes[startIdx], parentElm, refElm);21 }22}23function createElm (vnode, parentElm, refElm) {24 if (vnode.tag) {25 insert(parentElm, nodeOps.createElement(vnode.tag), refElm);26 } else {27 insert(parentElm, nodeOps.createTextNode(vnode.text), refElm);28 }29}30function removeVnodes (parentElm, vnodes, startIdx, endIdx) {31 for (; startIdx <= endIdx; ++startIdx) {32 const ch = vnodes[startIdx]33 if (ch) {34 removeNode(ch.elm);35 }36 }37}38function removeNode (el) {39 const parent = nodeOps.parentNode(el);40 if (parent) {41 nodeOps.removeChild(parent, el);42 }43}44function sameVnode () {45 return (46 a.key === b.key &&47 a.tag === b.tag &&48 a.isComment === b.isComment &&49 (!!a.data) === (!!b.data) &&50 sameInputType(a, b)51 )52}53function sameInputType (a, b) {54 if (a.tag !== 'input') return true55 let i56 const typeA = (i = a.data) && (i = i.attrs) && i.type57 const typeB = (i = b.data) && (i = i.attrs) && i.type58 return typeA === typeB59}60function patchVnode (oldVnode, vnode) {61 if (oldVnode === vnode) {62 return;63 }64 if (vnode.isStatic && oldVnode.isStatic && vnode.key === oldVnode.key) {65 vnode.elm = oldVnode.elm;66 vnode.componentInstance = oldVnode.componentInstance;67 return;68 }69 const elm = vnode.elm = oldVnode.elm;70 const oldCh = oldVnode.children;71 const ch = vnode.children;72 if (vnode.text) {73 nodeOps.setTextContent(elm, vnode.text);74 } else {75 if (oldCh && ch && (oldCh !== ch)) {76 updateChildren(elm, oldCh, ch);77 } else if (ch) {78 if (oldVnode.text) nodeOps.setTextContent(elm, '');79 addVnodes(elm, null, ch, 0, ch.length - 1);80 } else if (oldCh) {81 removeVnodes(elm, oldCh, 0, oldCh.length - 1)82 } else if (oldVnode.text) {83 nodeOps.setTextContent(elm, '')84 }85 }...

Full Screen

Full Screen

utils.dev.js

Source:utils.dev.js Github

copy

Full Screen

...56 // 如果refElm为null,则会添加到最后一项 相当于appendChild57 parentElm.insertBefore((0, _createElement["default"])(vnodes[i]), refElm);58 }59}60function removeVnodes(vnodes, startIdx, endIdx) {61 var parentElm = null;62 for (; startIdx <= endIdx; ++startIdx) {63 var ch = vnodes[startIdx];64 !parentElm && (parentElm = ch.elm.parentNode);65 parentElm && parentElm.removeChild(ch.elm);66 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { removeVnodes } = require('playwright/lib/protocol/dom.js');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const page = await context.newPage();7 const elementHandle = await page.$('h1');8 await removeVnodes(elementHandle);9 await browser.close();10})();11const { removeVnodes } = require('playwright/lib/protocol/dom.js');12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch({ headless: false });15 const context = await browser.newContext();16 const page = await context.newPage();17 const elementHandle = await page.$('h1');18 await removeVnodes(elementHandle, { childrenOnly: true });19 await browser.close();20})();21const { removeVnodes } = require('playwright/lib/protocol/dom.js');22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch({ headless: false });25 const context = await browser.newContext();26 const page = await context.newPage();27 const elementHandle = await page.$('h1');28 await removeVnodes(elementHandle, { childrenOnly: false });29 await browser.close();30})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { removeVnodes } = require('playwright/lib/server/dom.js');2const { chromium } = require('playwright');3const { expect } = require('chai');4(async () => {5 const browser = await chromium.launch();6 const page = await browser.newPage();7 await page.setContent(`<div id="parent">8</div>`);9 const parent = await page.$('#parent');10 const child1 = await page.$('#child1');11 const child2 = await page.$('#child2');12 const child3 = await page.$('#child3');13 removeVnodes(parent, child1, child3);14 const parentHTML = await parent.innerHTML();15 expect(parentHTML).to.equal('<div id="child3"></div>');16 await browser.close();17})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const path = require('path');2const { chromium } = require('playwright');3const { removeVnodes } = require('playwright/lib/server/dom.js');4(async () => {5 const browser = await chromium.launch({ headless: false });6 const context = await browser.newContext();7 const page = await context.newPage();8 const element = await page.$('input[name="q"]');9 await removeVnodes(element);10 await page.waitForTimeout(5000);11 await browser.close();12})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { removeVnodes } = require("playwright/lib/server/dom.js");2const { parse } = require("playwright/lib/server/common/html.js");3const html = `<html><body><div id="parent"><div id="child1"></div><div id="child2"></div></div></body></html>`;4const document = parse(html).documentElement;5const parent = document.querySelector("#parent");6const child1 = document.querySelector("#child1");7const child2 = document.querySelector("#child2");8removeVnodes(parent, child1, child2);9console.log(document.outerHTML);10const { removeVnodes } = require("playwright/lib/server/dom.js");11const { parse } = require("playwright/lib/server/common/html.js");12const html = `<html><body><div id="parent"><div id="child1"></div><div id="child2"></div></div></body></html>`;13const document = parse(html).documentElement;14const parent = document.querySelector("#parent");15const child1 = document.querySelector("#child1");16const child2 = document.querySelector("#child2");17removeVnodes(parent, child1, child2);18console.log(document.outerHTML);19const { removeVnodes } = require("playwright/lib/server/dom.js");20const { parse } = require("playwright/lib/server/common/html.js");21const html = `<html><body><div id="parent"><div id="child1"></div><div id="child2"></div></div></body></html>`;22const document = parse(html).documentElement;23const parent = document.querySelector("#parent");24const child1 = document.querySelector("#child1");25const child2 = document.querySelector("#child2");26removeVnodes(parent, child1, child2);27console.log(document.outerHTML);28const { removeVnodes } = require("playwright/lib/server/dom.js");29const { parse }

Full Screen

Using AI Code Generation

copy

Full Screen

1const { removeVnodes } = require('playwright/lib/server/dom.js');2removeVnodes([node]);3const { removeVnodes } = require('playwright/lib/server/dom.js');4removeVnodes([node]);5const { removeVnodes } = require('playwright/lib/server/dom.js');6removeVnodes([node]);7const { removeVnodes } = require('playwright/lib/server/dom.js');8removeVnodes([node]);9const { removeVnodes } = require('playwright/lib/server/dom.js');10removeVnodes([node]);11const { removeVnodes } = require('playwright/lib/server/dom.js');12removeVnodes([node]);13const { removeVnodes } = require('playwright/lib/server/dom.js');14removeVnodes([node]);15const { removeVnodes } = require('playwright/lib/server/dom.js');16removeVnodes([node]);17const { removeVnodes } = require('playwright/lib/server/dom.js');18removeVnodes([node]);19const { removeVnodes } = require('playwright/lib/server/dom.js');20removeVnodes([node]);21const { removeVnodes } = require('playwright

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful