mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
fix: effectScope should set scope
This commit is contained in:
parent
e34b0c9aca
commit
a0fc88ede1
2 changed files with 5 additions and 5 deletions
|
|
@ -324,9 +324,9 @@ local function effectScope(fn: () -> ...() -> ()?): () -> ()
|
||||||
if activeScope then
|
if activeScope then
|
||||||
link(e, activeScope)
|
link(e, activeScope)
|
||||||
end
|
end
|
||||||
local prev = setCurrentSub(e)
|
local prev = setCurrentScope(e)
|
||||||
local success, result = pcall(fn)
|
local success, result = pcall(fn)
|
||||||
setCurrentSub(prev)
|
setCurrentScope(prev)
|
||||||
if not success then
|
if not success then
|
||||||
error(result)
|
error(result)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ test("should run effect cleanup", function()
|
||||||
assert(cleanups == 1, "should skip redundant cleanup")
|
assert(cleanups == 1, "should skip redundant cleanup")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
test("should not run indirect effect cleanup", function()
|
test("should run indirect effect cleanup", function()
|
||||||
local cleanups = 0
|
local cleanups = 0
|
||||||
|
|
||||||
local cleanup
|
local cleanup
|
||||||
|
|
@ -58,9 +58,9 @@ test("should not run indirect effect cleanup", function()
|
||||||
|
|
||||||
assert(cleanups == 0, "should not cleanup immediately")
|
assert(cleanups == 0, "should not cleanup immediately")
|
||||||
stopScope()
|
stopScope()
|
||||||
assert(cleanups == 0, "should be detached from parent dispose")
|
assert(cleanups == 1, "should cleanup from parent dispose")
|
||||||
cleanup()
|
cleanup()
|
||||||
assert(cleanups == 1, "should cleanup after inner dispose")
|
assert(cleanups == 1, "should skip redundant dispose")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue