瀏覽代碼

refactor: more concise bitwise operations for flag removal (#7092)

花果山大圣 3 年之前
父節點
當前提交
4798a9f704
共有 2 個文件被更改,包括 6 次插入15 次删除
  1. 3 8
      packages/runtime-core/src/components/KeepAlive.ts
  2. 3 7
      packages/runtime-core/src/vnode.ts

+ 3 - 8
packages/runtime-core/src/components/KeepAlive.ts

@@ -424,14 +424,9 @@ function injectToKeepAliveRoot(
 }
 }
 
 
 function resetShapeFlag(vnode: VNode) {
 function resetShapeFlag(vnode: VNode) {
-  let shapeFlag = vnode.shapeFlag
-  if (shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
-    shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
-  }
-  if (shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {
-    shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE
-  }
-  vnode.shapeFlag = shapeFlag
+  // bitwise operations to remove keep alive flags
+  vnode.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
+  vnode.shapeFlag &= ~ShapeFlags.COMPONENT_KEPT_ALIVE
 }
 }
 
 
 function getInnerChild(vnode: VNode) {
 function getInnerChild(vnode: VNode) {

+ 3 - 7
packages/runtime-core/src/vnode.ts

@@ -358,13 +358,9 @@ export function isSameVNodeType(n1: VNode, n2: VNode): boolean {
     hmrDirtyComponents.has(n2.type as ConcreteComponent)
     hmrDirtyComponents.has(n2.type as ConcreteComponent)
   ) {
   ) {
     // #7042, ensure the vnode being unmounted during HMR
     // #7042, ensure the vnode being unmounted during HMR
-    if (n1.shapeFlag & ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE) {
-      n1.shapeFlag -= ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
-    }
-    // #7042, ensure the vnode being mounted as fresh during HMR
-    if (n2.shapeFlag & ShapeFlags.COMPONENT_KEPT_ALIVE) {
-      n2.shapeFlag -= ShapeFlags.COMPONENT_KEPT_ALIVE
-    }
+    // bitwise operations to remove keep alive flags
+    n1.shapeFlag &= ~ShapeFlags.COMPONENT_SHOULD_KEEP_ALIVE
+    n2.shapeFlag &= ~ShapeFlags.COMPONENT_KEPT_ALIVE
     // HMR only: if the component has been hot-updated, force a reload.
     // HMR only: if the component has been hot-updated, force a reload.
     return false
     return false
   }
   }