mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
Implement parent()
This commit is contained in:
parent
baf308ccf3
commit
c129153cd0
4 changed files with 118 additions and 1 deletions
26
src/_parent.luau
Normal file
26
src/_parent.luau
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
if not game then script = require "test/relative-string" end
|
||||
|
||||
local graph = require(script.Parent.graph)
|
||||
type Node<T> = graph.Node<T>
|
||||
|
||||
export type Source<T> = (() -> T) & ((value: T) -> T)
|
||||
|
||||
local function parent<T>(fn: () -> T): T
|
||||
local node = graph.get_scope()
|
||||
if not node then error("") end
|
||||
|
||||
local parent_node = node.owner
|
||||
if not parent_node then error("") end
|
||||
|
||||
graph.push_scope(parent_node :: Node<unknown>)
|
||||
|
||||
local ok, result = pcall(fn)
|
||||
|
||||
graph.pop_scope()
|
||||
|
||||
if not ok then error(result, 0) end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
return parent
|
||||
|
|
@ -9,7 +9,7 @@ local push_scope = graph.push_scope
|
|||
local pop_scope = graph.pop_scope
|
||||
local set_context = graph.set_context
|
||||
|
||||
export type Context<T> = (() -> T) & (<U>(T, () -> U) -> U)
|
||||
export type Context<T> = (() -> T) & (<U>(T, () -> U) -> U) & ((T, () -> ()) -> ())
|
||||
|
||||
local nil_symbol = newproxy()
|
||||
local count = 0
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ local effect = require(script.effect)
|
|||
local derive = require(script.derive)
|
||||
local cleanup = require(script.cleanup)
|
||||
local untrack = require(script.untrack)
|
||||
local parent = require(script._parent)
|
||||
local read = require(script.read)
|
||||
local batch = require(script.batch)
|
||||
local context = require(script.context)
|
||||
|
|
@ -68,6 +69,7 @@ local vide = {
|
|||
-- util
|
||||
cleanup = cleanup,
|
||||
untrack = untrack,
|
||||
parent = parent,
|
||||
read = read,
|
||||
batch = batch,
|
||||
context = context,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue