mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Make root() return destructor automatically
This commit is contained in:
parent
8142acd1c1
commit
82eec61c45
8 changed files with 26 additions and 30 deletions
|
|
@ -4,10 +4,9 @@ local root = require(script.Parent.root)
|
|||
local apply = require(script.Parent.apply)
|
||||
|
||||
local function mount<T>(component: () -> T, target: Instance?): () -> ()
|
||||
return root(function(destroy)
|
||||
return root(function()
|
||||
local result = component()
|
||||
if target then apply(target, { result }) end
|
||||
return destroy
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ local destroy = graph.destroy
|
|||
|
||||
local refs = {}
|
||||
|
||||
local function root<T...>(fn: (destroy: () -> ()) -> T...): T...
|
||||
local function root<T...>(fn: (destroy: () -> ()) -> T...): (() -> (), T...)
|
||||
local node = create_node(false, false, false)
|
||||
|
||||
refs[node] = true -- prevent gc of root node
|
||||
|
|
@ -33,7 +33,7 @@ local function root<T...>(fn: (destroy: () -> ()) -> T...): T...
|
|||
throw(`error while running root():\n\n{result[2]}`)
|
||||
end
|
||||
|
||||
return unpack(result :: any, 2)
|
||||
return destroy, unpack(result :: any, 2)
|
||||
end
|
||||
|
||||
return root :: (<T...>(fn: (destroy: () -> ()) -> T...) -> T...) & ((fn: (destroy: () -> ()) -> ()) -> ())
|
||||
return root :: <T...>(fn: (destroy: () -> ()) -> T...) -> (() -> (), T...)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue