From 1f0275f2b84d66fce7ccd4794d151668e4b79037 Mon Sep 17 00:00:00 2001 From: Tomasz Rejment Date: Fri, 1 Jul 2022 11:54:16 +0200 Subject: [PATCH] fix: allow to render array of elements in root component --- package-lock.json | 2 +- src/components/renderer/KopytkoDOM.brs | 2 +- .../kopytkoDOM/KopytkoDOM_updateDOM.test.brs | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4a188f1..c31e706 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@dazn/kopytko-framework", - "version": "1.0.2", + "version": "1.1.1", "license": "MIT", "dependencies": { "@dazn/kopytko-utils": "^2.0.1" diff --git a/src/components/renderer/KopytkoDOM.brs b/src/components/renderer/KopytkoDOM.brs index 131d23f..500e82e 100644 --- a/src/components/renderer/KopytkoDOM.brs +++ b/src/components/renderer/KopytkoDOM.brs @@ -64,7 +64,7 @@ function KopytkoDOM() as Object rootElement = m._getRootComponent() for each element in elements - if (element.parentId = Invalid) + if (Type(element) = "roArray" OR element.parentId = Invalid) parentElement = rootElement.top else parentElement = rootElement[element.parentId] diff --git a/src/components/renderer/_tests/kopytkoDOM/KopytkoDOM_updateDOM.test.brs b/src/components/renderer/_tests/kopytkoDOM/KopytkoDOM_updateDOM.test.brs index 7429941..cdc2419 100644 --- a/src/components/renderer/_tests/kopytkoDOM/KopytkoDOM_updateDOM.test.brs +++ b/src/components/renderer/_tests/kopytkoDOM/KopytkoDOM_updateDOM.test.brs @@ -92,6 +92,34 @@ function TestSuite__KopytkoDOM_updateDOM() return ts.assertEqual(renderedElement.id, "root", "The element marked to be rendered was not rendered") end function) + ts.addTest("it renders an array of elements", function (ts as Object) as String + ' Given + vNodes = [ + { + name: "LayoutGroup", + props: { id: "child1" }, + }, + { + name: "LayoutGroup", + props: { id: "child2" }, + } + ] + + diffResult = { + elementsToRender: [vNodes], + elementsToRemove: [], + elementsToUpdate: {}, + } + + ' When + ts.kopytkoDOM.updateDOM(diffResult) + + ' Then + childCount = m.top.getChildCount() + + return ts.assertEqual(childCount, vNodes.count(), "The elements marked to be rendered were not rendered") + end function) + ts.addTest("it removes the elements marked to be removed", function (ts as Object) as String ' Given ts.kopytkoDOM.renderElement({