mirror of
https://github.com/littensy/charm.git
synced 2026-10-24 06:51:37 +00:00
feat(sync): add preserveHistory option (#12)
* feat(sync): add `preserveHistory` option * build: omit project json from npm
This commit is contained in:
parent
acab2d3cce
commit
b68879cafd
9 changed files with 226 additions and 84 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue