mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
This commit is contained in:
parent
dafdc0739b
commit
470d2b5407
10 changed files with 242 additions and 450 deletions
|
|
@ -5,33 +5,25 @@ local throw = require(script.Parent.throw)
|
|||
local on_gc = require(script.Parent.on_gc)()
|
||||
local graph = require(script.Parent.graph)
|
||||
type Node<T> = graph.Node<T>
|
||||
local create = graph.create
|
||||
local init_scope = graph.init_scope
|
||||
local create_scope = graph.create_scope
|
||||
local open_scope = graph.open_scope
|
||||
local close_scope = graph.close_scope
|
||||
local get_scope = graph.get_scope
|
||||
local destroy = graph.destroy
|
||||
|
||||
local refs = {} :: { [Node<unknown>]: unknown }
|
||||
setmetatable(refs :: any, { __mode = "v" })
|
||||
|
||||
local function root<T>(fn: () -> T): T
|
||||
local function root<T>(fn: () -> T): (T, () -> ())
|
||||
assert(not get_scope())
|
||||
local scope = create_scope()
|
||||
|
||||
local node = create(nil) -- todo: lifetime with return vaue from fn
|
||||
|
||||
init_scope(node)
|
||||
open_scope(scope)
|
||||
|
||||
local v = fn()
|
||||
|
||||
close_scope()
|
||||
|
||||
refs[node] = v
|
||||
|
||||
on_gc(v, function()
|
||||
destroy(node)
|
||||
end)
|
||||
|
||||
return v
|
||||
return v, function()
|
||||
destroy(scope)
|
||||
end
|
||||
end
|
||||
|
||||
return root
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue