chore: prepare release candidate

This commit is contained in:
littensy 2025-11-15 20:38:15 -08:00
parent 29d8add265
commit ed9566bfff
14 changed files with 67 additions and 59 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@rbxts/charm-sync",
"version": "0.3.0",
"version": "0.4.0-rc.1",
"description": "Simple server-to-client sync for Charm",
"license": "MIT",
"main": "src/init.luau",

View file

@ -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 } },
})

View file

@ -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)

View file

@ -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,
}

View file

@ -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;
}

View file

@ -1,6 +1,6 @@
[package]
name = "littensy/charm-sync"
version = "0.3.0"
version = "0.4.0-rc.1"
registry = "https://github.com/UpliftGames/wally-index"
realm = "shared"
exclude = [
@ -12,4 +12,4 @@ exclude = [
]
[dependencies]
Charm = "littensy/charm@^0.10"
Charm = "littensy/charm@0.11.0-rc.1"