Match-id-d0e5ae18684fb3ef46de9d8df3806ec5e84da25b

This commit is contained in:
* 2022-03-23 10:28:58 +08:00 committed by *
parent dfa9ad8f02
commit c6f1debb03
6 changed files with 18 additions and 15 deletions

View File

@ -32,6 +32,8 @@ module.exports = {
es6: true,
},
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'accessor-pairs': 'off',
'brace-style': ['error', '1tbs'],
'func-style': ['warn', 'declaration', { allowArrowFunctions: true }],

View File

@ -165,7 +165,7 @@ function getChildByIndex(vNode: VNode, idx: number) {
// 从多个更新节点中,计算出开始节点。即:找到最近的共同的父辈节点
export function calcStartUpdateVNode(treeRoot: VNode) {
const toUpdateNodes = Array.from(treeRoot.toUpdateNodes);
const toUpdateNodes = [...treeRoot.toUpdateNodes];
if (toUpdateNodes.length === 0) {
return treeRoot;

View File

@ -1,7 +1,7 @@
import type { VNode } from '../Types';
import type { Hook } from './HookType';
let processingVNode: VNode = null;
let processingVNode: VNode | null = null;
// lastTimeHook是上一次执行func时产生的hooks中与currentHook对应的hook
let lastTimeHook: Hook<any, any> | null = null;
@ -13,7 +13,7 @@ export function getProcessingVNode() {
return processingVNode;
}
export function setProcessingVNode(vNode: VNode) {
export function setProcessingVNode(vNode: VNode | null) {
processingVNode = vNode;
}
@ -21,11 +21,11 @@ export function getLastTimeHook() {
return lastTimeHook;
}
export function setLastTimeHook(hook: Hook<any, any>) {
export function setLastTimeHook(hook: Hook<any, any> | null) {
lastTimeHook = hook;
}
export function setCurrentHook(hook: Hook<any, any>) {
export function setCurrentHook(hook: Hook<any, any> | null) {
currentHook = hook;
}

View File

@ -15,17 +15,17 @@ import {
setProcessingVNode,
setCurrentHook, getNextHook
} from './BaseHook';
import {useStateImpl,} from './UseStateHook';
import {useReducerImpl,} from './UseReducerHook';
import {useStateImpl} from './UseStateHook';
import {useReducerImpl} from './UseReducerHook';
import {HookStage, setHookStage} from './HookStage';
// hook对外入口
export function exeFunctionHook(
funcComp: (props: Object, arg: Object) => any,
props: Object,
arg: Object,
export function exeFunctionHook<Props extends Record<string, any>, Arg>(
funcComp: (props: Props, arg: Arg) => any,
props: Props,
arg: Arg,
processing: VNode,
): any {
) {
// 重置全局变量
resetGlobalVariable();
@ -39,13 +39,13 @@ export function exeFunctionHook(
processing.effectList = [];
// 设置hook阶段
if (processing.isCreated || !processing.oldHooks.length) {
if (processing.isCreated || !processing.oldHooks!.length) {
setHookStage(HookStage.Init);
} else {
setHookStage(HookStage.Update);
}
let comp = funcComp(props, arg);
const comp = funcComp(props, arg);
// 设置hook阶段为null用于判断hook是否在函数组件中调用
setHookStage(null);

View File

@ -10,6 +10,6 @@ export function getHookStage() {
return hookStage;
}
export function setHookStage(phase: HookStage) {
export function setHookStage(phase: HookStage| null) {
hookStage = phase;
}

View File

@ -4,6 +4,7 @@
"libs/*"
],
"scripts": {
"lint": "eslint . --ext .ts",
"build": " webpack --config ./scripts/webpack/webpack.config.js",
"build-3rdLib": "node ./scripts/gen3rdLib.js",
"build-3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js --dev",