diff --git a/src/maps.luau b/src/maps.luau index 5fea836..bd59a6c 100644 --- a/src/maps.luau +++ b/src/maps.luau @@ -61,6 +61,8 @@ local function indexes(input: () -> Map, transform: (() -> VI, local cv = input_cache[i] if cv ~= v then + input_cache[i] = v + if cv == nil then -- create new scope and run transform local scope = create_node(subowner, false, false) scopes[i] = scope :: Node @@ -87,8 +89,6 @@ local function indexes(input: () -> Map, transform: (() -> VI, input_nodes[i].cache = v update_descendants(input_nodes[i]) end - - input_cache[i] = v end end diff --git a/test/tests.luau b/test/tests.luau index 8f30a82..a0ba2ff 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -2646,10 +2646,12 @@ TEST("strict", wrap_root(function() do CASE "destruction of active scope" local src = source(false) + local count = 0 root(function() show(src, function() src(false) + vide.cleanup(function() count += 1 end) return {} end) end) @@ -2661,38 +2663,59 @@ TEST("strict", wrap_root(function() CHECK(not ok) end - -- todo: review intended behavior here - -- do CASE "destruction of active scope in indexes" - -- local src = source {} + do CASE "destruction of active scope in indexes" + local src = source {} - -- local tmp - -- root(function() - -- effect(function() - -- untrack(function() - -- tmp = indexes(src, function() - -- vide.cleanup(function() print "test" end) - -- src {} - -- print "updated" - -- vide.cleanup(function() print "test2" end) - -- print "end" - -- return {} - -- end) - -- return nil - -- end) - -- end) - -- end) + local count_1 = 0 + local count_2 = 0 - -- print "setting" + root(function() + effect(function() + untrack(function() + indexes(src, function() + vide.cleanup(function() count_1 += 1 end) + src {} + vide.cleanup(function() count_2 += 1 end) + return {} + end) + return nil + end) + end) + end) - -- local ok = pcall(function() - -- src { 1 } - -- print "done" - -- end) + local ok = pcall(function() + src { 1 } + end) - -- print(#tmp()) + CHECK(not ok) + end - -- CHECK(not ok) - -- end + do CASE "destruction of active scope in values" + local src = source {} + + local count_1 = 0 + local count_2 = 0 + + root(function() + effect(function() + untrack(function() + values(src, function() + vide.cleanup(function() count_1 += 1 end) + src {} + vide.cleanup(function() count_2 += 1 end) + return {} + end) + return nil + end) + end) + end) + + local ok = pcall(function() + src { {} } + end) + + CHECK(not ok) + end end)) local ok = FINISH()