Match-id-b706190bcb88c63440445159aa7872a1d220e7fb

This commit is contained in:
* 2023-02-21 18:54:53 +08:00
commit ef17f3065e
7 changed files with 38 additions and 18 deletions

View File

@ -1,3 +1,6 @@
## 0.0.39 (2023-02-21)
- **core**: #102 使用eview-react组件Dialog时关闭组件horizon报错且无法再打开弹框
## 0.0.38 (2023-02-01) ## 0.0.38 (2023-02-01)
- **core**: 增加flushSync接口 - **core**: 增加flushSync接口

View File

@ -20,3 +20,4 @@ declare var isDev: boolean;
declare var isTest: boolean; declare var isTest: boolean;
declare const __VERSION__: string; declare const __VERSION__: string;
declare var setImmediate: Function; declare var setImmediate: Function;
declare var __HORIZON_DEV_HOOK__: any;

View File

@ -4,7 +4,7 @@
"keywords": [ "keywords": [
"horizon" "horizon"
], ],
"version": "0.0.38", "version": "0.0.39",
"homepage": "", "homepage": "",
"bugs": "", "bugs": "",
"main": "index.js", "main": "index.js",

View File

@ -312,6 +312,7 @@ function recoverTreeContext(vNode: VNode) {
} }
parent = parent.parent; parent = parent.parent;
} }
contextProviders.forEach(node => { contextProviders.forEach(node => {
setContext(node, node.props.value); setContext(node, node.props.value);
}); });
@ -336,6 +337,7 @@ function resetTreeContext(vNode: VNode) {
function renderFromRoot(treeRoot) { function renderFromRoot(treeRoot) {
runAsyncEffects(); runAsyncEffects();
pushCurrentRoot(treeRoot); pushCurrentRoot(treeRoot);
// 1. 构建vNode树 // 1. 构建vNode树
buildVNodeTree(treeRoot); buildVNodeTree(treeRoot);
@ -346,6 +348,7 @@ function renderFromRoot(treeRoot) {
// 2. 提交变更 // 2. 提交变更
submitToRender(treeRoot); submitToRender(treeRoot);
popCurrentRoot(); popCurrentRoot();
if (window.__HORIZON_DEV_HOOK__) { if (window.__HORIZON_DEV_HOOK__) {
const hook = window.__HORIZON_DEV_HOOK__; const hook = window.__HORIZON_DEV_HOOK__;

View File

@ -89,7 +89,7 @@ export class VNode {
oldChild: VNode | null = null; oldChild: VNode | null = null;
promiseResolve: boolean; // suspense的promise是否resolve promiseResolve: boolean; // suspense的promise是否resolve
devProps: any; // 用于dev插件临时保存更新props值 devProps: any; // 用于dev插件临时保存更新props值
suspenseState: SuspenseState; suspenseState: SuspenseState | null;
path = ''; // 保存从根到本节点的路径 path = ''; // 保存从根到本节点的路径

View File

@ -17,15 +17,19 @@
* vNode的 * vNode的
*/ */
import type { VNode } from '../Types'; import type {VNode} from '../Types';
import { DomComponent, DomPortal, DomText, TreeRoot } from './VNodeTags'; import {DomComponent, DomPortal, DomText, TreeRoot} from './VNodeTags';
import { isComment } from '../../dom/utils/Common'; import {isComment} from '../../dom/utils/Common';
import { getNearestVNode } from '../../dom/DOMInternalKeys'; import {getNearestVNode} from '../../dom/DOMInternalKeys';
import { Addition, InitFlag } from './VNodeFlags'; import {Addition, InitFlag} from './VNodeFlags';
export function travelChildren(beginVNode: VNode, handleVNode: Function, isFinish?: Function) { export function travelChildren(
let node: VNode | null = beginVNode; beginVNode: VNode | null,
handleVNode: (node: VNode) => void,
isFinish?: (node: VNode) => boolean
) {
let node = beginVNode;
while (node !== null) { while (node !== null) {
if (isFinish && isFinish(node)) { if (isFinish && isFinish(node)) {
@ -41,15 +45,16 @@ export function travelChildren(beginVNode: VNode, handleVNode: Function, isFinis
// 从beginVNode开始深度遍历vNode树对每个vNode调用handleVNode方法 // 从beginVNode开始深度遍历vNode树对每个vNode调用handleVNode方法
export function travelVNodeTree( export function travelVNodeTree(
beginVNode: VNode, beginVNode: VNode,
handleVNode: Function, handleVNode: (node: VNode) => VNode | boolean | null | void,
childFilter: ((node: VNode) => boolean) | null, // 返回true不处理child childFilter: ((node: VNode) => boolean) | null, // 返回true不处理child
finishVNode: VNode, // 结束遍历节点有时候和beginVNode不相同 finishVNode: VNode, // 结束遍历节点有时候和beginVNode不相同
handleWhenToParent: Function | null handleWhenToParent: ((node: VNode) => void) | null
): VNode | null { ): VNode | boolean | null | void {
let node = beginVNode; let node = beginVNode;
while (true) { while (true) {
const ret = handleVNode(node); const ret = handleVNode(node);
// 如果处理一个vNode时有返回值则中断遍历 // 如果处理一个vNode时有返回值则中断遍历
if (ret) { if (ret) {
return ret; return ret;
@ -68,6 +73,8 @@ export function travelVNodeTree(
return null; return null;
} }
const isFun = typeof handleWhenToParent === 'function';
// 找兄弟,没有就往上再找兄弟 // 找兄弟,没有就往上再找兄弟
while (node.next === null) { while (node.next === null) {
if (node.parent === null || node.parent === finishVNode) { if (node.parent === null || node.parent === finishVNode) {
@ -75,8 +82,8 @@ export function travelVNodeTree(
} }
node = node.parent; node = node.parent;
if (typeof handleWhenToParent === 'function') { if (isFun) {
handleWhenToParent(node); handleWhenToParent!(node);
} }
} }
// 找到兄弟 // 找到兄弟
@ -89,14 +96,20 @@ export function travelVNodeTree(
// 置空vNode // 置空vNode
export function clearVNode(vNode: VNode) { export function clearVNode(vNode: VNode) {
vNode.isCleared = true; vNode.isCleared = true;
// 孩子节点的parent也置空
travelChildren(vNode.child, (node) => {
node.parent = null;
});
vNode.child = null; vNode.child = null;
vNode.parent = null;
vNode.next = null; vNode.next = null;
vNode.depContexts = null; vNode.depContexts = null;
vNode.dirtyNodes = null; vNode.dirtyNodes = null;
vNode.state = null; vNode.state = null;
vNode.hooks = null; vNode.hooks = null;
vNode.props = null; vNode.props = null;
vNode.parent = null;
vNode.suspenseState = null; vNode.suspenseState = null;
vNode.changeList = null; vNode.changeList = null;
vNode.effectList = null; vNode.effectList = null;
@ -129,7 +142,7 @@ function isDomContainer(vNode: VNode): boolean {
} }
export function findDomVNode(vNode: VNode): VNode | null { export function findDomVNode(vNode: VNode): VNode | null {
return travelVNodeTree( const ret = travelVNodeTree(
vNode, vNode,
node => { node => {
if (node.tag === DomComponent || node.tag === DomText) { if (node.tag === DomComponent || node.tag === DomText) {
@ -141,6 +154,8 @@ export function findDomVNode(vNode: VNode): VNode | null {
vNode, vNode,
null null
); );
return ret as VNode | null;
} }
export function findDOMByClassInst(inst) { export function findDOMByClassInst(inst) {

View File

@ -8,8 +8,6 @@
"prettier": "prettier -w libs/**/*.ts", "prettier": "prettier -w libs/**/*.ts",
"build": "rollup --config ./scripts/rollup/rollup.config.js", "build": "rollup --config ./scripts/rollup/rollup.config.js",
"build:watch": "rollup --watch --config ./scripts/rollup/rollup.config.js", "build:watch": "rollup --watch --config ./scripts/rollup/rollup.config.js",
"build:3rdLib": "node ./scripts/gen3rdLib.js build:3rdLib",
"build:3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js build:3rdLib-dev",
"build:horizon3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js build:horizon3rdLib-dev", "build:horizon3rdLib-dev": "npm run build & node ./scripts/gen3rdLib.js build:horizon3rdLib-dev",
"build-types": "tsc -p ./libs/horizon/index.ts --emitDeclarationOnly --declaration --declarationDir ./build/horizon/@types --skipLibCheck || echo \"WARNING: TSC exited with status $?\"", "build-types": "tsc -p ./libs/horizon/index.ts --emitDeclarationOnly --declaration --declarationDir ./build/horizon/@types --skipLibCheck || echo \"WARNING: TSC exited with status $?\"",
"debug-test": "yarn test --debug", "debug-test": "yarn test --debug",