diff --git a/test/tests.luau b/test/tests.luau index 1e5e074..f3ad794 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -1031,6 +1031,7 @@ end)) TEST("indexes()", wrap_root(function() local create = vide.create local source = vide.source + local effect = vide.effect local indexes = vide.indexes local cleanup = vide.cleanup @@ -1166,6 +1167,42 @@ TEST("indexes()", wrap_root(function() CHECK(n0 == n1) end + + -- practical example based on the graph - recursive update test + do CASE "recursive update" + local items = source { 1 } + + local updated = table.create(100, 0) + + local elements = indexes(items, function(item) + effect(function() + item() + updated[1] += 1 + end) + + effect(function() + item() + updated[2] += 1 + end) + end) + + effect(function() + items() + updated[3] += 1 + end) + + effect(function() + items() + updated[4] += 1 + end) + + items { 2 } + + CHECK(updated[1] == 2) + CHECK(updated[2] == 2) + CHECK(updated[3] == 2) + CHECK(updated[4] == 2) + end end)) TEST("values()", wrap_root(function()