mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 21:01:38 +00:00
fix(sync): block patches before initial hydration
This commit is contained in:
parent
f0acadb4e6
commit
d682efa94e
1 changed files with 10 additions and 1 deletions
|
|
@ -31,11 +31,20 @@ type ClientSyncer = {
|
|||
local function client(options: ClientOptions): ClientSyncer
|
||||
local atoms = options.atoms
|
||||
local self = {} :: ClientSyncer
|
||||
local ready = false
|
||||
|
||||
-- Apply the state changes sent by the server.
|
||||
function self:sync(...)
|
||||
for index = 1, select("#", ...) do
|
||||
local payload = select(index, ...)
|
||||
local payload: SyncPayload = select(index, ...)
|
||||
|
||||
if payload.type ~= "init" and not ready then
|
||||
-- If the client has not been hydrated yet, ignore patches.
|
||||
-- This is to prevent the client from patching incomplete state.
|
||||
continue
|
||||
end
|
||||
|
||||
ready = true
|
||||
|
||||
store.batch(function()
|
||||
for key, state in next, payload.data do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue