Match-id-96182a2cc2adbc3bd23f61c82f1ab0e9ec5446b8

This commit is contained in:
* 2022-10-17 15:49:31 +08:00 committed by *
parent 94820681d6
commit 2a438a2fe7
2 changed files with 27 additions and 3 deletions

View File

@ -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,

View File

@ -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;
}