mirror of
https://github.com/centau/vide.git
synced 2026-08-20 23:01:37 +00:00
fix fragments in effects
This commit is contained in:
parent
72e5fbb6fe
commit
1f76b66ff9
2 changed files with 13 additions and 3 deletions
|
|
@ -11,6 +11,7 @@ local graph = require(script.Parent.graph)
|
||||||
type Node<T> = graph.Node<T>
|
type Node<T> = graph.Node<T>
|
||||||
|
|
||||||
type Array<V> = { V }
|
type Array<V> = { V }
|
||||||
|
type ArrayOrV<V> = {ArrayOrV<V>} | V
|
||||||
type Map<K, V> = { [K]: V }
|
type Map<K, V> = { [K]: V }
|
||||||
|
|
||||||
local free_caches: {
|
local free_caches: {
|
||||||
|
|
@ -124,7 +125,7 @@ local function apply<T>(instance: T & Instance, properties: { [unknown]: unknown
|
||||||
end
|
end
|
||||||
elseif type(property) == "number" then
|
elseif type(property) == "number" then
|
||||||
if type(value) == "function" then
|
if type(value) == "function" then
|
||||||
bind.children(instance, value :: () -> Instance | Array<Instance>) -- bind children
|
bind.children(instance, value :: () -> ArrayOrV<Instance>) -- bind children
|
||||||
elseif type(value) == "table" then
|
elseif type(value) == "table" then
|
||||||
if is_action(value) then
|
if is_action(value) then
|
||||||
table.insert(actions[(value :: any).priority], (value :: any).callback :: () -> ()) -- add action to buffer
|
table.insert(actions[(value :: any).priority], (value :: any).callback :: () -> ()) -- add action to buffer
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ type ChildrenBinding = {
|
||||||
children: () -> Instance | { Instance }
|
children: () -> Instance | { Instance }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ArrayOrV<V> = V | { V }
|
||||||
local function update_children_effect(p: ChildrenBinding)
|
local function update_children_effect(p: ChildrenBinding)
|
||||||
local cur_children_set: { [Instance]: true } = p.cur_children_set -- cache of all children parented before update
|
local cur_children_set: { [Instance]: true } = p.cur_children_set -- cache of all children parented before update
|
||||||
local new_child_set: { [Instance]: true } = p.new_children_set -- cache of all children parented after update
|
local new_child_set: { [Instance]: true } = p.new_children_set -- cache of all children parented after update
|
||||||
|
|
@ -48,8 +49,14 @@ local function update_children_effect(p: ChildrenBinding)
|
||||||
new_children = { new_children }
|
new_children = { new_children }
|
||||||
end
|
end
|
||||||
|
|
||||||
if new_children then
|
local function process_child(child: ArrayOrV<Instance>)
|
||||||
for _, child in next, new_children :: { Instance } do
|
if type(child) == "table" then
|
||||||
|
for _, child in next, child do
|
||||||
|
process_child(child)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if new_child_set[child] then return end -- stops redundant reparenting
|
||||||
|
|
||||||
new_child_set[child] = true -- record child set from this update
|
new_child_set[child] = true -- record child set from this update
|
||||||
if not cur_children_set[child] then
|
if not cur_children_set[child] then
|
||||||
child.Parent = p.instance -- if child wasn't already parented then parent it
|
child.Parent = p.instance -- if child wasn't already parented then parent it
|
||||||
|
|
@ -59,6 +66,8 @@ local function update_children_effect(p: ChildrenBinding)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
process_child(new_children)
|
||||||
|
|
||||||
for child in next, cur_children_set do
|
for child in next, cur_children_set do
|
||||||
child.Parent = nil -- unparent all children that weren't in the new children set
|
child.Parent = nil -- unparent all children that weren't in the new children set
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue