Match-id-50484ea25531ddb0401803d9939d3ffa068a783f

This commit is contained in:
* 2022-02-23 14:15:01 +08:00 committed by *
parent 5dd5a50663
commit 46c4e406b1
2 changed files with 4 additions and 12 deletions

View File

@ -46,9 +46,8 @@ function mountInstance(clazz, processing: VNode, nextProps: object) {
} }
// 构造实例 // 构造实例
callConstructor(processing, clazz, nextProps); const inst = callConstructor(processing, clazz, nextProps);
const inst = processing.realNode;
inst.props = nextProps; inst.props = nextProps;
inst.state = processing.state; inst.state = processing.state;
inst.context = getCurrentContext(clazz, processing); inst.context = getCurrentContext(clazz, processing);
@ -121,18 +120,13 @@ export function captureClassComponent(processing: VNode, clazz: any, nextProps:
const newContext = getCurrentContext(clazz, processing); const newContext = getCurrentContext(clazz, processing);
// 子节点抛出异常时如果本class是个捕获异常的处理节点这时候oldProps是null所以需要使用props // 子节点抛出异常时如果本class是个捕获异常的处理节点这时候oldProps是null所以需要使用props
let oldProps = (processing.flags & DidCapture) === DidCapture ? processing.props : processing.oldProps; const oldProps = (processing.flags & DidCapture) === DidCapture ? processing.props : processing.oldProps;
if (processing.isLazyComponent) {
oldProps = mergeDefaultProps(processing.type, oldProps);
}
inst.props = oldProps;
if (oldProps !== processing.props || inst.context !== newContext) { if (oldProps !== processing.props || inst.context !== newContext) {
// 在已挂载的组件接收新的 props 之前被调用 // 在已挂载的组件接收新的 props 之前被调用
callComponentWillReceiveProps(inst, nextProps, newContext); callComponentWillReceiveProps(inst, nextProps, newContext);
} }
inst.state = processing.state;
processUpdates(processing, inst, nextProps); processUpdates(processing, inst, nextProps);
// 如果 props, state, context 都没有变化且 isForceUpdate 为 false则不需要更新 // 如果 props, state, context 都没有变化且 isForceUpdate 为 false则不需要更新

View File

@ -24,12 +24,10 @@ const LifecycleEffectArr = Update | Callback | Ref | Snapshot;
export class FlagUtils { export class FlagUtils {
static removeFlag(node: VNode, flag: number) { static removeFlag(node: VNode, flag: number) {
const flags = node.flags; node.flags &= ~flag;
node.flags = flags & (~flag);
} }
static removeLifecycleEffectFlags(node) { static removeLifecycleEffectFlags(node) {
const flags = node.flags; node.flags &= ~LifecycleEffectArr;
node.flags = flags & (~LifecycleEffectArr);
} }
static hasAnyFlag(node: VNode) { // 有标志位 static hasAnyFlag(node: VNode) { // 有标志位
return node.flags !== InitFlag; return node.flags !== InitFlag;