mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 03:36:11 +00:00
chore: prepare release candidate
This commit is contained in:
parent
29d8add265
commit
ed9566bfff
14 changed files with 67 additions and 59 deletions
|
|
@ -13,7 +13,7 @@ test("should hydrate atom", function()
|
|||
local a = Charm.atom(1)
|
||||
|
||||
client.addSignals({ a = a })
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "init", data = { a = 2 } },
|
||||
})
|
||||
|
||||
|
|
@ -25,13 +25,13 @@ test("should merge patch", function()
|
|||
local previous = a()
|
||||
|
||||
client.addSignals({ a = a })
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "init", data = { a = a() } },
|
||||
})
|
||||
|
||||
assert(a() == previous, "should set a to the initial value")
|
||||
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "patch", data = { a = { b = 3 } } },
|
||||
})
|
||||
|
||||
|
|
@ -44,14 +44,14 @@ test("should fix sparse array patches", function()
|
|||
local a = Charm.atom({ 1 })
|
||||
|
||||
client.addSignals({ a = a })
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "init", data = { a = a() } },
|
||||
})
|
||||
|
||||
-- This patch would be the result of a diff between { 1 } and { 1, 2 } that
|
||||
-- was JSON-serialized and deserialized. The client should be able to catch
|
||||
-- this and convert the string key back to a number.
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "patch", data = { a = { ["2"] = 2 } } },
|
||||
})
|
||||
|
||||
|
|
@ -69,11 +69,11 @@ test("should merge multiple patches", function()
|
|||
table.insert(calls, value)
|
||||
end)
|
||||
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "init", data = { a = a() } },
|
||||
})
|
||||
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "patch", data = { a = 2 } },
|
||||
{ type = "patch", data = { a = 3 } },
|
||||
})
|
||||
|
|
@ -97,11 +97,11 @@ test("should batch patches", function()
|
|||
states.a = a()
|
||||
end)
|
||||
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "init", data = { a = a(), b = b() } },
|
||||
})
|
||||
|
||||
client.hydrate({
|
||||
client.patch({
|
||||
{ type = "patch", data = { a = 1, b = 2 } },
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ test("should replicate server state to client", function()
|
|||
server.addSignalsToClient(target, { a = serverA, b = serverB })
|
||||
server.connect(function(syncTarget, payloads)
|
||||
if syncTarget == target then
|
||||
client.hydrate(payloads)
|
||||
client.patch(payloads)
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ test("should replicate historical server state to client", function()
|
|||
server.addSignalsToClient(target, { a = serverA, b = serverB })
|
||||
server.connect(function(syncTarget, payloads)
|
||||
if syncTarget == target then
|
||||
client.hydrate(payloads)
|
||||
client.patch(payloads)
|
||||
end
|
||||
end)
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ end
|
|||
--- initializing it with the full state or merging a partial patch.
|
||||
---
|
||||
--- @param payloads The state updates received from the server.
|
||||
local function hydrate(payloads: { SyncPayload })
|
||||
local function patch(payloads: { SyncPayload })
|
||||
debug.profilebegin("CharmSync")
|
||||
for _, payload in payloads do
|
||||
if payload.type == "init" then
|
||||
Charm.batch(applyInitPayload, payload.data)
|
||||
|
|
@ -70,11 +71,12 @@ local function hydrate(payloads: { SyncPayload })
|
|||
Charm.batch(applyPatchPayload, payload.data)
|
||||
end
|
||||
end
|
||||
debug.profileend()
|
||||
end
|
||||
|
||||
return {
|
||||
addSignals = addSignals,
|
||||
removeSignals = removeSignals,
|
||||
removeAllSignals = removeAllSignals,
|
||||
hydrate = hydrate,
|
||||
patch = patch,
|
||||
}
|
||||
|
|
|
|||
6
packages/charm-sync/src/index.d.ts
vendored
6
packages/charm-sync/src/index.d.ts
vendored
|
|
@ -1,4 +1,4 @@
|
|||
import { Atom, Getter, Setter } from "@rbxts/charm";
|
||||
import { Atom, Setter } from "@rbxts/charm";
|
||||
|
||||
type Key = string | number | symbol;
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ export interface None {
|
|||
|
||||
export type MaybeNone<T> = undefined extends T ? None : never;
|
||||
|
||||
type GetterMap = Record<string, Getter<any>>;
|
||||
type GetterMap = Record<string, () => any>;
|
||||
type SetterMap = Record<string, Setter<any>>;
|
||||
|
||||
/**
|
||||
|
|
@ -134,7 +134,7 @@ export namespace client {
|
|||
*
|
||||
* @param payloads The state updates received from the server.
|
||||
*/
|
||||
export function hydrate<Getters extends GetterMap = GetterMap, FixArrays extends boolean = true>(
|
||||
export function patch<Getters extends GetterMap = GetterMap, FixArrays extends boolean = true>(
|
||||
payloads: SyncPayload<Getters, FixArrays>[],
|
||||
): void;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue