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)
- **core**: 增加flushSync接口

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,8 +8,6 @@
"prettier": "prettier -w libs/**/*.ts",
"build": "rollup --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-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",