mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 20:54:08 +00:00
fix(charm-sync): run addSignalsToClient outside tracking scope
This commit is contained in:
parent
73fbfb2685
commit
c31e5c5a34
2 changed files with 28 additions and 1 deletions
|
|
@ -61,7 +61,7 @@ local function trackSignal<T>(key: string, getter: () -> T, identifier: unknown)
|
||||||
local rawInitialValue = toRaw(initialValue)
|
local rawInitialValue = toRaw(initialValue)
|
||||||
local snapshot = if initialValue ~= rawInitialValue then utils.deepCopy(rawInitialValue) else initialValue
|
local snapshot = if initialValue ~= rawInitialValue then utils.deepCopy(rawInitialValue) else initialValue
|
||||||
|
|
||||||
local dispose = Charm.effect(function()
|
local dispose = Charm.untracked(Charm.effect, function()
|
||||||
local newValue = getter()
|
local newValue = getter()
|
||||||
local rawValue = toRaw(newValue)
|
local rawValue = toRaw(newValue)
|
||||||
local isReactive = newValue ~= rawValue
|
local isReactive = newValue ~= rawValue
|
||||||
|
|
|
||||||
|
|
@ -405,4 +405,31 @@ test.describe("historical", function()
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
test("addSignalsToClient should ignore tracking context", function()
|
||||||
|
local counter = Charm.atom(0)
|
||||||
|
local payloads: { any }?
|
||||||
|
|
||||||
|
server.connect(function(_client, _payloads)
|
||||||
|
payloads = _payloads
|
||||||
|
end)
|
||||||
|
|
||||||
|
local dispose = Charm.effectScope(function()
|
||||||
|
server.addSignalsToClient("PLAYER_ID", { counter = counter })
|
||||||
|
end)
|
||||||
|
|
||||||
|
server.flush()
|
||||||
|
assert(payloads, "Expected payloads to be sent")
|
||||||
|
assert(payloads[1].type == "init", "Expected first payload to be init")
|
||||||
|
assert(payloads[1].data.counter == 0, "Expected init payload to contain atom 'counter'")
|
||||||
|
|
||||||
|
dispose()
|
||||||
|
|
||||||
|
payloads = nil
|
||||||
|
counter(1)
|
||||||
|
server.flush()
|
||||||
|
assert(payloads, "Expected payloads to be sent")
|
||||||
|
assert(payloads[1].type == "patch", "Expected first payload to be patch")
|
||||||
|
assert(payloads[1].data.counter == 1, "Expected patch payload to contain atom 'counter'")
|
||||||
|
end)
|
||||||
|
|
||||||
return {}
|
return {}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue