mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
change approach flush_update_queue
This commit is contained in:
parent
ffab944f44
commit
fe9a92e336
2 changed files with 18 additions and 19 deletions
|
|
@ -6,18 +6,18 @@ local graph = require(script.Parent.graph)
|
||||||
|
|
||||||
local function batch(setter: () -> ())
|
local function batch(setter: () -> ())
|
||||||
local already_batching = flags.batch
|
local already_batching = flags.batch
|
||||||
local flush
|
local from
|
||||||
|
|
||||||
if not already_batching then
|
if not already_batching then
|
||||||
flags.batch = true
|
flags.batch = true
|
||||||
flush = graph.flush_update_queue()
|
from = graph.get_graph_length()
|
||||||
end
|
end
|
||||||
|
|
||||||
local ok, err: string? = pcall(setter)
|
local ok, err: string? = pcall(setter)
|
||||||
|
|
||||||
if not already_batching then
|
if not already_batching then
|
||||||
flags.batch = false
|
flags.batch = false
|
||||||
flush()
|
graph.flush_update_queue(from)
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ok then throw(`error occured while batching updates: {err}`) end
|
if not ok then throw(`error occured while batching updates: {err}`) end
|
||||||
|
|
|
||||||
|
|
@ -184,12 +184,12 @@ local function queue_children_for_update<T>(node: SourceNode<T>)
|
||||||
update_queue.n = i
|
update_queue.n = i
|
||||||
end
|
end
|
||||||
|
|
||||||
local function flush_update_queue()
|
local function get_graph_length()
|
||||||
local n0 = update_queue.n
|
return update_queue.n
|
||||||
|
end
|
||||||
|
|
||||||
return function()
|
local function flush_update_queue(from: number)
|
||||||
|
local i = from + 1
|
||||||
local i = n0 + 1
|
|
||||||
while i <= update_queue.n do
|
while i <= update_queue.n do
|
||||||
local node = update_queue[i]
|
local node = update_queue[i]
|
||||||
--assert(node.effect)
|
--assert(node.effect)
|
||||||
|
|
@ -202,9 +202,7 @@ local function flush_update_queue()
|
||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
update_queue.n = n0
|
update_queue.n = from
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_descendants<T>(root: SourceNode<T>)
|
local function update_descendants<T>(root: SourceNode<T>)
|
||||||
|
|
@ -284,5 +282,6 @@ return table.freeze {
|
||||||
create_source_node = create_source_node,
|
create_source_node = create_source_node,
|
||||||
get_children = get_children,
|
get_children = get_children,
|
||||||
flush_update_queue = flush_update_queue,
|
flush_update_queue = flush_update_queue,
|
||||||
|
get_graph_length = get_graph_length,
|
||||||
scopes = scopes
|
scopes = scopes
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue