From 51054786c26f487f338400a0c0b20bc0f75734c3 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Mon, 6 Jul 2020 14:21:55 +0100 Subject: [PATCH] fix: list supports multiple children (without container) --- packages/client/src/render/attachChildren.js | 41 ++++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/packages/client/src/render/attachChildren.js b/packages/client/src/render/attachChildren.js index 3e4ebef103..95db47710e 100644 --- a/packages/client/src/render/attachChildren.js +++ b/packages/client/src/render/attachChildren.js @@ -30,34 +30,33 @@ export const attachChildren = initialiseOpts => (htmlElement, options) => { } } + const contextArray = Array.isArray(context) ? context : [context] + const childNodes = [] - for (let childProps of treeNode.props._children) { - const { componentName, libName } = splitName(childProps._component) - if (!componentName || !libName) return + for (let context of contextArray) { + for (let childProps of treeNode.props._children) { + const { componentName, libName } = splitName(childProps._component) - const ComponentConstructor = componentLibraries[libName][componentName] + if (!componentName || !libName) return - const prepareNodes = ctx => { - const childNodesThisIteration = prepareRenderComponent({ - props: childProps, - parentNode: treeNode, - ComponentConstructor, - htmlElement, - anchor, - context: ctx, - }) + const ComponentConstructor = componentLibraries[libName][componentName] - for (let childNode of childNodesThisIteration) { - childNodes.push(childNode) + const prepareNodes = ctx => { + const childNodesThisIteration = prepareRenderComponent({ + props: childProps, + parentNode: treeNode, + ComponentConstructor, + htmlElement, + anchor, + context: ctx, + }) + + for (let childNode of childNodesThisIteration) { + childNodes.push(childNode) + } } - } - if (Array.isArray(context)) { - for (let singleCtx of context) { - prepareNodes(singleCtx) - } - } else { prepareNodes(context) } }