mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
28 lines
694 B
Lua
28 lines
694 B
Lua
if not game then script = require "test/relative-string" end
|
|
|
|
local graph = require(script.Parent.graph)
|
|
local set_effect = graph.set_effect
|
|
local capture = graph.capture
|
|
|
|
local function watch(effect: () -> ()): () -> ()
|
|
local nodes = capture(effect :: () -> nil)
|
|
|
|
-- store aside captured nodes in new table
|
|
nodes = table.clone(nodes)
|
|
|
|
-- register effect with permanent lifetime
|
|
for _, node in next, nodes do
|
|
set_effect(node, effect, true)
|
|
end
|
|
|
|
local function unwatch()
|
|
-- unregister effect from all nodes
|
|
for _, node in next, nodes do
|
|
set_effect(node, effect, nil)
|
|
end
|
|
end
|
|
|
|
return unwatch
|
|
end
|
|
|
|
return watch
|