mirror of
https://github.com/littensy/charm.git
synced 2026-10-21 11:44:08 +00:00
chore: prepare release candidate
This commit is contained in:
parent
29d8add265
commit
ed9566bfff
14 changed files with 67 additions and 59 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@rbxts/charm",
|
||||
"version": "0.10.0",
|
||||
"version": "0.11.0-rc.1",
|
||||
"description": "Atomic state management based on alien-signals",
|
||||
"license": "MIT",
|
||||
"main": "src/init.luau",
|
||||
|
|
|
|||
|
|
@ -367,10 +367,10 @@ end
|
|||
--- @see https://github.com/littensy/charm?tab=readme-ov-file#atominitialValue-equals
|
||||
local function atom<T>(initialValue: T, equals: ((current: T, incoming: T) -> boolean)?): Atom<T>
|
||||
local getter, setter = signal(initialValue, equals)
|
||||
local function atomGetterSetter(...)
|
||||
local function atomOper(...)
|
||||
return if select("#", ...) == 0 then getter() else setter((...))
|
||||
end
|
||||
return atomGetterSetter
|
||||
return atomOper
|
||||
end
|
||||
|
||||
--- Creates a new read-only signal that is computed based on the values of
|
||||
|
|
@ -565,7 +565,7 @@ end
|
|||
--- @return A computed signal that tracks the value returned by the getter.
|
||||
local function toSignal<T>(fn: () -> T): () -> T
|
||||
local name = debug.info(fn, "n")
|
||||
return if name == "signalGetter" or name == "computedGetter" or name == "atomGetterSetter" then fn else computed(fn)
|
||||
return if name == "signalGetter" or name == "computedGetter" or name == "atomOper" then fn else computed(fn)
|
||||
end
|
||||
|
||||
--- Creates an effect that runs the callback one immediately, and then again
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "littensy/charm"
|
||||
version = "0.10.0"
|
||||
version = "0.11.0-rc.1"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
exclude = ["node_modules", "src/__tests__", "src/index.d.ts", "package.json"]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@rbxts/react-charm",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0-rc.1",
|
||||
"description": "React bindings for Charm state management",
|
||||
"license": "MIT",
|
||||
"main": "src/init.luau",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "littensy/react-charm"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0-rc.1"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
exclude = [
|
||||
|
|
@ -13,5 +13,5 @@ exclude = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
Charm = "littensy/charm@^0.10"
|
||||
Charm = "littensy/charm@0.11.0-rc.1"
|
||||
React = "jsdotlua/react@^17"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@rbxts/vide-charm",
|
||||
"version": "0.3.0",
|
||||
"version": "0.4.0-rc.1",
|
||||
"description": "Vide bindings for Charm state management",
|
||||
"license": "MIT",
|
||||
"main": "src/init.luau",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "littensy/vide-charm"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0-rc.1"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "shared"
|
||||
exclude = [
|
||||
|
|
@ -13,5 +13,5 @@ exclude = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
Charm = "littensy/charm@^0.10"
|
||||
Charm = "littensy/charm@0.11.0-rc.1"
|
||||
Vide = "centau/vide@^0.3"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue