feat(sync): add preserveHistory option (#12)

* feat(sync): add `preserveHistory` option

* build: omit project json from npm
This commit is contained in:
richard 2024-07-08 13:47:50 -07:00 • committed by GitHub
parent acab2d3cce
commit b68879cafd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 226 additions and 84 deletions

View file

@ -15,9 +15,9 @@ type ClientSyncer = {
Applies a patch or initializes the state of the atoms with the given
payload from the server.
@param payload The patch or hydration payload to apply.
@param ...payloads The patches or hydration payloads to apply.
]=]
sync: (self: ClientSyncer, payload: SyncPayload) -> (),
sync: (self: ClientSyncer, ...SyncPayload) -> (),
}
--[=[
@ -32,12 +32,16 @@ local function client(options: ClientOptions): ClientSyncer
local self = {} :: ClientSyncer
-- Apply the state changes sent by the server.
function self:sync(payload)
for key, state in payload.data do
if payload.type == "patch" then
atoms[key](patch.apply(atoms[key](), state))
else
atoms[key](state)
function self:sync(...)
for index = 1, select("#", ...) do
local payload = select(index, ...)
for key, state in payload.data do
if payload.type == "patch" then
atoms[key](patch.apply(atoms[key](), state))
else
atoms[key](state)
end
end
end
end