From 2a438a2fe756f5054d8196e8fe87da6062b49fbd Mon Sep 17 00:00:00 2001 From: * <8> Date: Mon, 17 Oct 2022 15:49:31 +0800 Subject: [PATCH 1/2] Match-id-96182a2cc2adbc3bd23f61c82f1ab0e9ec5446b8 --- libs/horizon/index.ts | 3 +++ libs/horizon/src/external/HorizonIs.ts | 27 +++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/libs/horizon/index.ts b/libs/horizon/index.ts index ebd80121..e715cf13 100644 --- a/libs/horizon/index.ts +++ b/libs/horizon/index.ts @@ -49,6 +49,7 @@ import { isContextProvider, isContextConsumer, isElement, + isValidElementType, isForwardRef, isFragment, isLazy, @@ -113,6 +114,7 @@ const Horizon = { watch, isFragment, isElement, + isValidElementType, isForwardRef, isLazy, isMemo, @@ -163,6 +165,7 @@ export { // 兼容ReactIs isFragment, isElement, + isValidElementType, isForwardRef, isLazy, isMemo, diff --git a/libs/horizon/src/external/HorizonIs.ts b/libs/horizon/src/external/HorizonIs.ts index 8e3a4ccc..7cb4369f 100644 --- a/libs/horizon/src/external/HorizonIs.ts +++ b/libs/horizon/src/external/HorizonIs.ts @@ -28,6 +28,13 @@ function isObject(anyThing) { return Object.prototype.toString.call(anyThing) === '[object Object]'; } +function isBuiltinTag(type: any) { + return [TYPE_FRAGMENT, TYPE_SUSPENSE].includes(type); +} + +function isBuiltinComponent(type: any) { + return [TYPE_MEMO, TYPE_PROVIDER, TYPE_LAZY, TYPE_FORWARD_REF, TYPE_CONTEXT].includes(type); +} /** * 获取传入的element的类型 * 1. fragment, suspense 属于内置标签,类型位于type @@ -39,17 +46,17 @@ function isObject(anyThing) { function getType(ele: any) { if (isObject(ele)) { const type = ele.type; - if ([TYPE_FRAGMENT, TYPE_SUSPENSE].includes(type)) { + if (isBuiltinTag(type)) { return type; } const vtypeOfType = type?.vtype; - if ([TYPE_MEMO, TYPE_PROVIDER, TYPE_LAZY, TYPE_FORWARD_REF, TYPE_CONTEXT].includes(vtypeOfType)) { + if (isBuiltinComponent(vtypeOfType)) { return vtypeOfType; } const vtype = ele.vtype; - if(TYPE_PORTAL === vtype) { + if (TYPE_PORTAL === vtype) { return vtype; } } @@ -89,3 +96,17 @@ export function isContextProvider(ele: any) { export function isContextConsumer(ele: any) { return getType(ele) === TYPE_CONTEXT; } + +export function isValidElementType(type: any) { + if (typeof type === 'string' || typeof type === 'function' || isBuiltinTag(type)) { + return true; + } + + if (isObject(type)) { + if (isBuiltinComponent(type.vtype)) { + return true; + } + } + + return false; +} From c773b91dbae4d7b8c274eba8bd3d3a8543247371 Mon Sep 17 00:00:00 2001 From: * <8> Date: Mon, 17 Oct 2022 15:51:52 +0800 Subject: [PATCH 2/2] Match-id-c84c340a0c26d2228d1aaf5ccd35ad91dad1d997 --- CHANGELOG.md | 3 +++ libs/horizon/package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8d338d8..10f970ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.0.23 (2022-09-23) +- **core**: #86 兼容ReactIs API +- ## 0.0.22 (2022-09-22) - **core**: #83 #75 #72 input支持受控 diff --git a/libs/horizon/package.json b/libs/horizon/package.json index 0950fd50..8b0f2127 100644 --- a/libs/horizon/package.json +++ b/libs/horizon/package.json @@ -4,7 +4,7 @@ "keywords": [ "horizon" ], - "version": "0.0.22", + "version": "0.0.23", "homepage": "", "bugs": "", "main": "index.js",