diff --git a/src/graph.luau b/src/graph.luau index cdc00cc..dac2e09 100644 --- a/src/graph.luau +++ b/src/graph.luau @@ -58,6 +58,11 @@ local function get_scope(): Node? return scopes[scopes.n] end +local function bump_update_id() + update_id += 1 + return update_id +end + local function assert_stable_scope(): Node local scope = get_scope() @@ -246,9 +251,8 @@ local function flush_update_queue(from: number) update_queue.n = from end -local function update_descendants(root: SourceNode, is_root_update: boolean?) +local function update_descendants(root: SourceNode) local n0 = update_queue.n - if is_root_update and not flags.batch then update_id += 1 end queue_children_for_update(root) if flags.batch then return end @@ -324,6 +328,7 @@ return table.freeze { flush_update_queue = flush_update_queue, get_update_queue_length = get_update_queue_length, set_context = set_context, + bump_update_id = bump_update_id, scopes = scopes, q = update_queue diff --git a/src/maps.luau b/src/maps.luau index 2150939..6add44b 100644 --- a/src/maps.luau +++ b/src/maps.luau @@ -86,7 +86,8 @@ local function indexes(input: () -> Map, transform: (() -> VI, output_cache[i] = result else -- update source input_nodes[i].cache = v - update_descendants(input_nodes[i], true) + graph.bump_update_id() + update_descendants(input_nodes[i]) end end end @@ -170,7 +171,8 @@ local function values(input: () -> Map, transform: (VI, () -> else -- update source if cv ~= i then input_nodes[v].cache = i - update_descendants(input_nodes[v], true) + graph.bump_update_id() + update_descendants(input_nodes[v]) end cur_input_cache[v] = nil diff --git a/src/source.luau b/src/source.luau index 36c4609..3341362 100644 --- a/src/source.luau +++ b/src/source.luau @@ -21,7 +21,8 @@ local function source(initial_value: T): Source end node.cache = v - update_descendants(node, true) + graph.bump_update_id() + update_descendants(node) return v end diff --git a/src/spring.luau b/src/spring.luau index 936a18f..47af352 100644 --- a/src/spring.luau +++ b/src/spring.luau @@ -285,7 +285,8 @@ local function update_spring_sources() output.cache = vec6_to_type[typeof(data.source_value)](x0_123, x0_456) end - update_descendants(output, true) + graph.bump_update_id() + update_descendants(output) end end diff --git a/test/tests.luau b/test/tests.luau index c808de2..4b50483 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -36,6 +36,7 @@ vide.strict = false TEST("graph", function() local create_node = graph.create_node local push_child_to_scope = graph.push_child_to_scope + local bump_update_id = graph.bump_update_id local update_descendants = graph.update_descendants local push_child = graph.push_child local get_scope = graph.get_scope @@ -98,9 +99,13 @@ TEST("graph", function() pop_scope() CHECK(count == 1) - update_descendants(a, true) + + bump_update_id() + update_descendants(a) CHECK(count == 2) - update_descendants(b, true) + + bump_update_id() + update_descendants(b) CHECK(count == 3) end @@ -119,7 +124,8 @@ TEST("graph", function() push_scope(c); push_child_to_scope(a); pop_scope() push_scope(d); push_child_to_scope(b); push_child_to_scope(c); pop_scope() - update_descendants(a, true) + bump_update_id() + update_descendants(a) CHECK(b_cnt == 1) CHECK(c_cnt == 1) @@ -138,7 +144,8 @@ TEST("graph", function() push_scope(c); assert(type(c.effect) == "function" and c.effect)(NIL); pop_scope() - update_descendants(a, true) + bump_update_id() + update_descendants(a) CHECK(#get_children(a) == 1) CHECK(#get_children(b) == 1) @@ -286,14 +293,16 @@ TEST("graph", function() local a, b, c, d, e, f = node(root), node(root), node(root), node(root), node(root), node(root) function b.effect(x) - update_descendants(d, true) + bump_update_id() + update_descendants(d) return not x end push_child(a, b); push_child(a, c) push_child(d, e); push_child(d, f) - update_descendants(a, true) + bump_update_id() + update_descendants(a) CHECK(true) end