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)
|
## 0.0.22 (2022-09-22)
|
||||||
- **core**: #83 #75 #72 input支持受控
|
- **core**: #83 #75 #72 input支持受控
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,7 @@ import {
|
||||||
isContextProvider,
|
isContextProvider,
|
||||||
isContextConsumer,
|
isContextConsumer,
|
||||||
isElement,
|
isElement,
|
||||||
|
isValidElementType,
|
||||||
isForwardRef,
|
isForwardRef,
|
||||||
isFragment,
|
isFragment,
|
||||||
isLazy,
|
isLazy,
|
||||||
|
@ -113,6 +114,7 @@ const Horizon = {
|
||||||
watch,
|
watch,
|
||||||
isFragment,
|
isFragment,
|
||||||
isElement,
|
isElement,
|
||||||
|
isValidElementType,
|
||||||
isForwardRef,
|
isForwardRef,
|
||||||
isLazy,
|
isLazy,
|
||||||
isMemo,
|
isMemo,
|
||||||
|
@ -163,6 +165,7 @@ export {
|
||||||
// 兼容ReactIs
|
// 兼容ReactIs
|
||||||
isFragment,
|
isFragment,
|
||||||
isElement,
|
isElement,
|
||||||
|
isValidElementType,
|
||||||
isForwardRef,
|
isForwardRef,
|
||||||
isLazy,
|
isLazy,
|
||||||
isMemo,
|
isMemo,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"horizon"
|
"horizon"
|
||||||
],
|
],
|
||||||
"version": "0.0.22",
|
"version": "0.0.23",
|
||||||
"homepage": "",
|
"homepage": "",
|
||||||
"bugs": "",
|
"bugs": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
|
|
@ -28,6 +28,13 @@ function isObject(anyThing) {
|
||||||
return Object.prototype.toString.call(anyThing) === '[object Object]';
|
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的类型
|
* 获取传入的element的类型
|
||||||
* 1. fragment, suspense 属于内置标签,类型位于type
|
* 1. fragment, suspense 属于内置标签,类型位于type
|
||||||
|
@ -39,17 +46,17 @@ function isObject(anyThing) {
|
||||||
function getType(ele: any) {
|
function getType(ele: any) {
|
||||||
if (isObject(ele)) {
|
if (isObject(ele)) {
|
||||||
const type = ele.type;
|
const type = ele.type;
|
||||||
if ([TYPE_FRAGMENT, TYPE_SUSPENSE].includes(type)) {
|
if (isBuiltinTag(type)) {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vtypeOfType = type?.vtype;
|
const vtypeOfType = type?.vtype;
|
||||||
if ([TYPE_MEMO, TYPE_PROVIDER, TYPE_LAZY, TYPE_FORWARD_REF, TYPE_CONTEXT].includes(vtypeOfType)) {
|
if (isBuiltinComponent(vtypeOfType)) {
|
||||||
return vtypeOfType;
|
return vtypeOfType;
|
||||||
}
|
}
|
||||||
|
|
||||||
const vtype = ele.vtype;
|
const vtype = ele.vtype;
|
||||||
if(TYPE_PORTAL === vtype) {
|
if (TYPE_PORTAL === vtype) {
|
||||||
return vtype;
|
return vtype;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,3 +96,17 @@ export function isContextProvider(ele: any) {
|
||||||
export function isContextConsumer(ele: any) {
|
export function isContextConsumer(ele: any) {
|
||||||
return getType(ele) === TYPE_CONTEXT;
|
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