mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
This commit is contained in:
parent
fe3af737be
commit
dafdc0739b
10 changed files with 249 additions and 550 deletions
|
|
@ -2,20 +2,38 @@ if not game then script = require "test/relative-string" end
|
|||
|
||||
local graph = require(script.Parent.graph)
|
||||
local create = graph.create
|
||||
local capture_and_link = graph.capture_and_link
|
||||
local create_and_open_scope = graph.create_and_open_scope
|
||||
local capture = graph.capture
|
||||
local add_child = graph.add_child
|
||||
local set_effect = graph.set_effect
|
||||
local update = graph.update
|
||||
local track = graph.track
|
||||
local init_scope = graph.init_scope
|
||||
local close_scope = graph.close_scope
|
||||
|
||||
local function derive<T>(fn: () -> T): () -> T
|
||||
local node, read_node_value = create((false :: any) :: T)
|
||||
local node = create((false :: any) :: T)
|
||||
|
||||
create_and_open_scope(node)
|
||||
init_scope(node)
|
||||
|
||||
node.cache = capture_and_link(node, fn)
|
||||
local nodes, value = capture(fn)
|
||||
|
||||
close_scope()
|
||||
|
||||
return read_node_value
|
||||
for _, parent in next, nodes do
|
||||
add_child(parent, node)
|
||||
end
|
||||
|
||||
set_effect(node, function()
|
||||
node.cache = fn()
|
||||
update(node)
|
||||
end)
|
||||
|
||||
node.cache = value
|
||||
|
||||
return function()
|
||||
track(node)
|
||||
return node.cache
|
||||
end
|
||||
end
|
||||
|
||||
return derive
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue