Skip to content

Commit

Permalink
improved normalization process
Browse files Browse the repository at this point in the history
  • Loading branch information
trueadm committed Dec 4, 2016
1 parent c86bed5 commit 56bfd11
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/core/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,20 @@ export function normalizeVNodes(nodes: any[]): VNode[] {
return newNodes || nodes as VNode[];
}

function normalizeChildren(children) {
if (isArray(children)) {
return normalizeVNodes(children);
} else if (isVNode(children) && children.dom) {
return cloneVNode(children);
}
return children;
}

function normalize(vNode) {
const props = vNode.props;
const children = vNode.children;

//convert a wrongly created type back to element
// convert a wrongly created type back to element
if (isString(vNode.type) && (vNode.flags & VNodeFlags.Component)) {
vNode.flags = VNodeFlags.Element;
}
Expand All @@ -136,11 +145,10 @@ function normalize(vNode) {
}
}
if (!isInvalid(children)) {
if (isArray(children)) {
vNode.children = normalizeVNodes(children);
} else if (isVNode(children) && children.dom) {
vNode.children = cloneVNode(children);
}
vNode.children = normalizeChildren(children);
}
if (props && !isInvalid(props.children)) {
props.children = normalizeChildren(props.children);
}
}

Expand Down

0 comments on commit 56bfd11

Please sign in to comment.