mirror of
https://github.com/centau/vide.git
synced 2026-08-20 14:41:37 +00:00
Add special case for frozen tables
Sources will now check if frozen tables are equal before updating dependencies.
This commit is contained in:
parent
744cce0fb6
commit
afd863285b
3 changed files with 23 additions and 1 deletions
|
|
@ -15,7 +15,7 @@ local function source<T>(value: T): Source<T>
|
|||
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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
1
todo.md
1
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue