From c6d9b9978a80e47c4da431699cb2a6a1d3483ab6 Mon Sep 17 00:00:00 2001 From: George Cook Date: Fri, 30 Dec 2022 15:23:56 +0100 Subject: [PATCH 1/2] Adds map support to an aa --- src/source/core/Collections.bs | 39 +++++++++++++++++++++-------- src/source/core/Collections.spec.bs | 19 ++++++++++++++ 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/source/core/Collections.bs b/src/source/core/Collections.bs index d055b158..a2755100 100644 --- a/src/source/core/Collections.bs +++ b/src/source/core/Collections.bs @@ -37,19 +37,36 @@ namespace mc.collections end if if array <> invalid isClass = mc.isClass(mapper) - for each item in array - if isClass - transformed = mapper.transform(item) - if transformed <> invalid - items.push(transformed) + if mc.isArray(array) or type(array) = "roSGNode" + for each item in array + if isClass + transformed = mapper.transform(item) + if transformed <> invalid + items.push(transformed) + end if + else + transformed = mc.apply(mapper, [item], mTarget) + if transformed <> invalid + items.push(transformed) + end if end if - else - transformed = mc.apply(mapper, [item], mTarget) - if transformed <> invalid - items.push(transformed) + end for + else + 'is an aa + for each key in array + if isClass + transformed = mapper.transform(key, array[key]) + if transformed <> invalid + items.push(transformed) + end if + else + transformed = mc.apply(mapper, [key, array[key]], mTarget) + if transformed <> invalid + items.push(transformed) + end if end if - end if - end for + end for + end if end if return items end function diff --git a/src/source/core/Collections.spec.bs b/src/source/core/Collections.spec.bs index e0542c79..4c527658 100644 --- a/src/source/core/Collections.spec.bs +++ b/src/source/core/Collections.spec.bs @@ -453,6 +453,25 @@ namespace tests m.assertEqual(foundItem, expected) end function + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + @describe("map") + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + @it("maps with value predicate") + function _() + codes = ["US", "DE", "FR", "UK"] + expected = ["_US", "_DE", "_FR", "_UK"] + m.assertEqual(mc.collections.map(codes, function(item): return "_" + item: end function), expected) + end function + + @it("maps associative array") + function _() + codes = { "US": "United States", "DE": "Germany", "FR": "France", "UK": "United Kingdom" } + expected = ["_UK_United Kingdom", "_FR_France", "_DE_Germany", "_US_United States"] + + m.assertEqual(mc.collections.map(codes, function(key, value): return "_" + key + "_" + value: end function), expected) + end function + '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ @describe("filter") '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ From 6f9b2d230b22311698d6456439211c5a530cc8fd Mon Sep 17 00:00:00 2001 From: George Cook Date: Fri, 30 Dec 2022 15:24:10 +0100 Subject: [PATCH 2/2] fixes a npe issue --- src/source/ml/ItemViewManager.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/source/ml/ItemViewManager.bs b/src/source/ml/ItemViewManager.bs index 97dbb9ea..46ec8065 100644 --- a/src/source/ml/ItemViewManager.bs +++ b/src/source/ml/ItemViewManager.bs @@ -700,7 +700,7 @@ namespace ml end function protected function getIndexAfterItemUpdate(previousInfo as ml.CellInfo) as integer - if previousInfo.index = -1 + if previousInfo = invalid or previousInfo.index = -1 return 0 end if