(component): 整理 vueUtil 工具, 常用插槽解析与类型判断

This commit is contained in:
就眠儀式
2022-11-23 04:43:46 +08:00
parent d97ad261f3
commit 753ef0fab2
4 changed files with 32 additions and 40 deletions

View File

@@ -1,3 +1,4 @@
export * from "./domUtil";
export * from "./withInstall";
export * from "./arrayUtil";
export * from "./vueUtil";

View File

@@ -0,0 +1,27 @@
import { Component, VNode, VNodeTypes } from "vue";
export enum ShapeFlags {
ELEMENT = 1,
FUNCTIONAL_COMPONENT = 1 << 1,
STATEFUL_COMPONENT = 1 << 2,
COMPONENT = ShapeFlags.STATEFUL_COMPONENT | ShapeFlags.FUNCTIONAL_COMPONENT,
TEXT_CHILDREN = 1 << 3,
ARRAY_CHILDREN = 1 << 4,
SLOTS_CHILDREN = 1 << 5,
TELEPORT = 1 << 6,
SUSPENSE = 1 << 7,
COMPONENT_SHOULD_KEEP_ALIVE = 1 << 8,
COMPONENT_KEPT_ALIVE = 1 << 9,
}
export const isElement = (vn: VNode) => {
return Boolean(vn && vn.shapeFlag & ShapeFlags.ELEMENT);
};
export const isComponent = (vn: VNode, type?: VNodeTypes): type is Component => {
return Boolean(vn && vn.shapeFlag & ShapeFlags.COMPONENT);
};
export const isArrayChildren = (vn: VNode, children: VNode["children"]): children is VNode[] => {
return Boolean(vn && vn.shapeFlag & ShapeFlags.ARRAY_CHILDREN);
};