mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
subsequent updates do not batch test case
This commit is contained in:
parent
f74462192b
commit
2959b5c3ad
1 changed files with 17 additions and 71 deletions
|
|
@ -1922,86 +1922,32 @@ TEST("batch()", wrap_root(function()
|
||||||
CHECK(b3() == 4)
|
CHECK(b3() == 4)
|
||||||
end
|
end
|
||||||
|
|
||||||
do CASE "recursive queue flush"
|
do CASE "subsequent updates do not batch"
|
||||||
|
|
||||||
local a0 = source(0)
|
local a = source(0)
|
||||||
|
local b = source(0)
|
||||||
|
local c = source(0)
|
||||||
|
local d = source(0)
|
||||||
|
local d_n = 0
|
||||||
|
|
||||||
-- this effect should only update every time a0() is set
|
|
||||||
local changes = { a = 0, b = 0, c = 0, d = 0, e = 0 }
|
|
||||||
effect(function()
|
effect(function()
|
||||||
a0()
|
c()
|
||||||
changes.a += 1
|
d()
|
||||||
|
d_n += 1
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- we first check if a0() works normally
|
effect(function()
|
||||||
a0(1)
|
c(a())
|
||||||
CHECK(changes.a == 2)
|
d(b())
|
||||||
a0(2)
|
end)
|
||||||
CHECK(changes.a == 3)
|
|
||||||
|
|
||||||
-- we batch the sets to check if batch works normally
|
|
||||||
batch(function()
|
batch(function()
|
||||||
a0(3)
|
a(1)
|
||||||
a0(4)
|
b(1)
|
||||||
end)
|
|
||||||
-- since the previous updates are batched, it should now have 3 updates in total
|
|
||||||
CHECK(changes.a == 4)
|
|
||||||
|
|
||||||
local b0 = source(0)
|
|
||||||
local b1 = source(0)
|
|
||||||
|
|
||||||
-- now lets add a effect that updates another effect
|
|
||||||
-- this effect tracks a0(), and updates b0() and b1() in a batch
|
|
||||||
-- originally, recursive queue flush would be triggered here since it
|
|
||||||
-- would reprocess the entire queue.
|
|
||||||
effect(function()
|
|
||||||
batch(function()
|
|
||||||
b0(a0())
|
|
||||||
b1(a0())
|
|
||||||
end)
|
|
||||||
changes.b += 1
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local c0 = source(0)
|
CHECK(d_n == 3)
|
||||||
local c1 = source(0)
|
|
||||||
|
|
||||||
-- we add another effect that tracks b0 and b1 updates
|
|
||||||
-- it then updates c0 and c1, which should not be batched
|
|
||||||
effect(function()
|
|
||||||
-- this should not batch
|
|
||||||
c0(b0())
|
|
||||||
c1(b1())
|
|
||||||
changes.c += 1
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- lets set a0() again to check if b0() and b1() are properly batched
|
|
||||||
-- this used to perform a recursive queue flush since we run batch inside
|
|
||||||
-- a effect previously, which would make batch rerun the effect
|
|
||||||
-- updating a0 once should mean effect2 only updated once
|
|
||||||
a0(1)
|
|
||||||
CHECK(changes.b == 2)
|
|
||||||
CHECK(changes.c == 2)
|
|
||||||
a0(2)
|
|
||||||
CHECK(changes.b == 3)
|
|
||||||
CHECK(changes.c == 3)
|
|
||||||
|
|
||||||
-- this tracks how often c0 and c1 are updated
|
|
||||||
effect(function()
|
|
||||||
c0()
|
|
||||||
c1()
|
|
||||||
changes.d += 1
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- updates that happen after batch should not batch.
|
|
||||||
-- this checks to make sure that isn't the case
|
|
||||||
a0(1)
|
|
||||||
CHECK(changes.b == 4)
|
|
||||||
CHECK(changes.c == 4)
|
|
||||||
CHECK(changes.d == 3)
|
|
||||||
a0(2)
|
|
||||||
CHECK(changes.b == 5)
|
|
||||||
CHECK(changes.c == 5)
|
|
||||||
CHECK(changes.d == 5)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
do CASE "recursive queue flush diamond A,B,C,D"
|
do CASE "recursive queue flush diamond A,B,C,D"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue