Match-id-a708470cc29a9a37b97ce2d0b3230589836ef191
This commit is contained in:
commit
9062203441
|
@ -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支持受控
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"keywords": [
|
||||
"horizon"
|
||||
],
|
||||
"version": "0.0.22",
|
||||
"version": "0.0.23",
|
||||
"homepage": "",
|
||||
"bugs": "",
|
||||
"main": "index.js",
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue