mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
This commit is contained in:
parent
866135b152
commit
e776183452
10 changed files with 480 additions and 367 deletions
|
|
@ -1,20 +1,25 @@
|
|||
if not game then script = require "test/relative-string" end
|
||||
|
||||
local create = require(script.Parent.create)
|
||||
local graph = require(script.Parent.graph)
|
||||
type Node<T> = graph.Node<T>
|
||||
local refs = graph.refs
|
||||
local create_node = graph.create_node
|
||||
local get_stack_scope = graph.get_stack_scope
|
||||
local open_scope = graph.open_scope
|
||||
local close_scope = graph.close_scope
|
||||
|
||||
local non_tracking_scope = create_node(false)
|
||||
|
||||
local function untrack<T>(source: () -> T): T
|
||||
local initial = #refs
|
||||
local scope = get_stack_scope(1)
|
||||
|
||||
local value = source()
|
||||
open_scope(scope or non_tracking_scope)
|
||||
|
||||
-- remove any references made since `untrack()` was called
|
||||
for i = initial, #refs do
|
||||
refs[i] = nil
|
||||
end
|
||||
local v = source()
|
||||
|
||||
return value
|
||||
close_scope()
|
||||
|
||||
return v
|
||||
end
|
||||
|
||||
return untrack
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue