diff --git a/src/source.luau b/src/source.luau index e4a94a4..edb323a 100644 --- a/src/source.luau +++ b/src/source.luau @@ -15,7 +15,7 @@ local function source(value: T): Source if select("#", ...) == 0 then return get_value() end local v = ... :: T - if node.cache == v and type(v) ~= "table" then return v end + if node.cache == v and (type(v) ~= "table" or table.isfrozen(v)) then return v end set(node, v) return v diff --git a/test/tests.luau b/test/tests.luau index 068d33b..f3c965e 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -192,6 +192,27 @@ TEST("source()", function() state(state()) CHECK(updates == 1) end + + do CASE "does not update if same value is frozen table" + local a = table.freeze {} + local b = table.freeze {} + + local state = source(a) + + local updates = -1 + watch(function() + state() + updates += 1 + end) + + CHECK(updates == 0) + state(a) + CHECK(updates == 0) + state(b) + CHECK(updates == 1) + state(b) + CHECK(updates == 1) + end end) TEST("derive()", function() diff --git a/todo.md b/todo.md index 3303508..c1f3cc4 100644 --- a/todo.md +++ b/todo.md @@ -14,5 +14,6 @@ - [ ] untrack - [ ] batch - [ ] async/resource/loading/suspense + - [ ] stores - define order with nested properties - review alternative to nested properties, merge function