1.1.3 • Published 4 years ago
@comall/work-in-progress v1.1.3
WorkInProgress
可视化协议转换 ReactElement 的基础库,并应用于任何基于 react-reconciler 实现的渲染器。
Class
WorkInProgress 构造函数接收一个组件Map,key为协议定义的名,value为组件。
new WorkInProgress({
'view': View
});WorkInProgress 实例方法:
- transformIntoReactElement,接收 CoMallElement,返回 ReactElement
- transformIntoCoMallElement 接收 ReactElement Tree,返回 CoMallElement
- registerComponent 注册一个组件,参数为key,component
警告:Tree 层级被限制为三层,超过三层的 CoMallElement将会被忽略
WorkInProgress 使用案例可访问:WorkInProgress
Function
createCoMallElement函数,创建并返回一个 CoMallElement。
createCoMallElement(
type,
[props],
[...children]
)创建并返回指定类型的新的 CoMallElement,其中type参数类型必须为字符串。
cloneCoMallElement函数,以 CoMallElement 元素为样板克隆并返回新的 CoMallElement 元素。
cloneCoMallElement(
element,
[props],
[...children]
)返回元素的 props 是将新的 props 与原始元素的 props 浅层合并后的结果,新的子元素将取代现有的子元素。
createSnapshot函数,传入一个 CoMallElement 元素,并返回一个JSX格式的快照,如<CoMallElement><CoMallElement/>。
createSnapshot(
element
)isValidCoMallElement验证对象是否为CoMall元素,返回值为true或false。
isValidCoMallElement(object)Children
Children 提供了处理 props.children 不透明数据结构的实用方法。
Children.map在children里的每一个节点上调用一个函数。
!!!警告:由于转换规则三层的限制,从根元素开始计算 child 需要应用在三层以内
const maps = Children.map(treeMock.props.children, (child) => {
return (
<View>
<View>{child}</View>
</View>
);
});Children.count返回children中的组件数量Children.only验证children是否只有一个子节点
Distribute
数据分发容器,详细可访问:Distribute
技术分析
1.1.3
4 years ago