Skip to content

Commit

Permalink
Merge pull request #287 from georgejecook/feat/adds-map-support-for-aa
Browse files Browse the repository at this point in the history
Feat/adds map support for aa
  • Loading branch information
georgejecook authored Dec 30, 2022
2 parents 55dc092 + 6f9b2d2 commit b0d48c5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
39 changes: 28 additions & 11 deletions src/source/core/Collections.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions src/source/core/Collections.spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Expand Down
2 changes: 1 addition & 1 deletion src/source/ml/ItemViewManager.bs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b0d48c5

Please sign in to comment.