mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Initial commit
This commit is contained in:
commit
cb002f4f27
50 changed files with 4666 additions and 0 deletions
25
src/source.luau
Normal file
25
src/source.luau
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
if not game then script = require "test/wrap-require" end
|
||||
|
||||
local graph = require(script.Parent.graph)
|
||||
type Node<T> = graph.Node<T>
|
||||
local create = graph.create
|
||||
local set = graph.set
|
||||
|
||||
|
||||
type Source<T> = (() -> T) & ((T) -> T)
|
||||
|
||||
local function source<T>(value: T): Source<T>
|
||||
local node, get_value = create(value :: T)
|
||||
|
||||
return function(...): T
|
||||
if select("#", ...) == 0 then return get_value() end
|
||||
|
||||
local v = ... :: T
|
||||
if node.cache == v and type(v) ~= "table" then return v end
|
||||
|
||||
set(node, v)
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
return source :: (<T>(value: T) -> Source<T>) & (<T>() -> Source<T>)
|
||||
Loading…
Add table
Add a link
Reference in a new issue