mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
untrack now passes arguments to the callback
This commit is contained in:
parent
558505cd71
commit
c00791d7a0
2 changed files with 10 additions and 3 deletions
|
|
@ -2,7 +2,7 @@ local graph = require "./graph"
|
||||||
type Node<T> = graph.Node<T>
|
type Node<T> = graph.Node<T>
|
||||||
local get_scope = graph.get_scope
|
local get_scope = graph.get_scope
|
||||||
|
|
||||||
local function untrack<T>(source: () -> T): T
|
local function untrack<T, U...>(source: () -> T, ...: U...): T
|
||||||
local scope = get_scope()
|
local scope = get_scope()
|
||||||
|
|
||||||
if scope then
|
if scope then
|
||||||
|
|
@ -10,7 +10,7 @@ local function untrack<T>(source: () -> T): T
|
||||||
local effect = scope.effect
|
local effect = scope.effect
|
||||||
scope.effect = false
|
scope.effect = false
|
||||||
|
|
||||||
local ok, result = xpcall(source, debug.traceback)
|
local ok, result = xpcall(source, debug.traceback, ...)
|
||||||
|
|
||||||
scope.effect = effect :: () -> ()
|
scope.effect = effect :: () -> ()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1938,6 +1938,13 @@ TEST("untrack()", wrap_root(function()
|
||||||
|
|
||||||
CHECK(cleaned_count == 2)
|
CHECK(cleaned_count == 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
do CASE "passes values"
|
||||||
|
untrack(function(a, b)
|
||||||
|
CHECK(a == 1)
|
||||||
|
CHECK(b == 2)
|
||||||
|
end, 1, 2)
|
||||||
|
end
|
||||||
end))
|
end))
|
||||||
|
|
||||||
TEST("events", function()
|
TEST("events", function()
|
||||||
|
|
@ -2464,7 +2471,7 @@ TEST("context()", function()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
TEST("nested effects cases", function()
|
TEST("nested effects cases", function()
|
||||||
local vide = require "../../vide"
|
local vide = require "../src/lib"
|
||||||
local source = vide.source
|
local source = vide.source
|
||||||
local effect = vide.effect
|
local effect = vide.effect
|
||||||
local untrack = vide.untrack
|
local untrack = vide.untrack
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue