mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Update indexes() test
This commit is contained in:
parent
250c13e7b8
commit
520b0cca32
1 changed files with 37 additions and 0 deletions
|
|
@ -1031,6 +1031,7 @@ end))
|
||||||
TEST("indexes()", wrap_root(function()
|
TEST("indexes()", wrap_root(function()
|
||||||
local create = vide.create
|
local create = vide.create
|
||||||
local source = vide.source
|
local source = vide.source
|
||||||
|
local effect = vide.effect
|
||||||
local indexes = vide.indexes
|
local indexes = vide.indexes
|
||||||
local cleanup = vide.cleanup
|
local cleanup = vide.cleanup
|
||||||
|
|
||||||
|
|
@ -1166,6 +1167,42 @@ TEST("indexes()", wrap_root(function()
|
||||||
|
|
||||||
CHECK(n0 == n1)
|
CHECK(n0 == n1)
|
||||||
end
|
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))
|
end))
|
||||||
|
|
||||||
TEST("values()", wrap_root(function()
|
TEST("values()", wrap_root(function()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue