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

This commit is contained in:
花果山大圣 2022-11-11 09:15:37 +08:00 committed by GitHub
parent 845efbbb5d
commit 4798a9f704
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 15 deletions

View File

@ -424,14 +424,9 @@ function injectToKeepAliveRoot(
}
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) {

View File

@ -358,13 +358,9 @@ export function isSameVNodeType(n1: VNode, n2: VNode): boolean {
hmrDirtyComponents.has(n2.type as ConcreteComponent)
) {
// #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.
return false
}