mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
This commit is contained in:
parent
d353f71619
commit
0d542c66a6
10 changed files with 76 additions and 105 deletions
|
|
@ -6,26 +6,17 @@ local create_node = graph.create_node
|
|||
local set_owner = graph.set_owner
|
||||
local track = graph.track
|
||||
local get_scope = graph.get_scope
|
||||
local open_scope = graph.open_scope
|
||||
local close_scope = graph.close_scope
|
||||
|
||||
local evaluate_node = graph.evaluate_node
|
||||
|
||||
local function derive<T>(fn: () -> T): () -> T
|
||||
local owner = get_scope()
|
||||
if not owner then throw("cannot derive in non-reactive scope") end
|
||||
assert(owner)
|
||||
|
||||
local node = create_node((false :: any) :: T)
|
||||
node.effect = function()
|
||||
return fn()
|
||||
end
|
||||
local node = create_node(false :: any, fn)
|
||||
|
||||
set_owner(node, owner)
|
||||
open_scope(node)
|
||||
|
||||
node.cache = fn()
|
||||
|
||||
close_scope()
|
||||
evaluate_node(node)
|
||||
|
||||
return function()
|
||||
track(node)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue