mirror of
https://github.com/centau/vide.git
synced 2026-10-20 17:34:08 +00:00
Fix effect updating its own source looping in strict mode
This commit is contained in:
parent
bafdd3b243
commit
a74452f46e
2 changed files with 16 additions and 1 deletions
|
|
@ -175,7 +175,7 @@ local update_queue = { n = 0 } :: { n: number, [number]: Node<any> }
|
|||
local function try_evaluate_node<T>(node: Node<T>): (boolean, string?)
|
||||
if flags.strict then
|
||||
if table.find(scopes, node) then
|
||||
error("a scope, that should rerun due to the update of a source, is already active", 0)
|
||||
return false, "a scope, that should rerun due to the update of a source, is already active"
|
||||
end
|
||||
|
||||
local initial_value = node.cache
|
||||
|
|
|
|||
|
|
@ -3171,6 +3171,21 @@ TEST("strict", wrap_root(function()
|
|||
CHECK(count == 4)
|
||||
end
|
||||
|
||||
do CASE "effect updating its own source"
|
||||
local src = source(0)
|
||||
local count = 0
|
||||
|
||||
effect(function()
|
||||
count += 1
|
||||
if count > 100 then return end
|
||||
local v = src()
|
||||
if v > 0 then src(v + 1) end
|
||||
end)
|
||||
|
||||
CHECK(not pcall(src, 1))
|
||||
CHECK(count < 100)
|
||||
end
|
||||
|
||||
do CASE "destruction of active scope"
|
||||
local src = source(false)
|
||||
local count = 0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue