mirror of
https://github.com/littensy/charm.git
synced 2026-10-20 17:51:37 +00:00
fix(sync): block patches before initial hydration (#21)
This commit is contained in:
parent
f0acadb4e6
commit
9ba552cb6c
6 changed files with 37 additions and 16 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
|
@ -18,8 +18,8 @@ jobs:
|
||||||
with:
|
with:
|
||||||
version: 8.15.4
|
version: 8.15.4
|
||||||
|
|
||||||
- name: Install Aftman
|
- name: Install Rokit
|
||||||
uses: ok-nick/setup-aftman@v0.4.2
|
uses: CompeyDev/setup-rokit@v0.1.2
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: |
|
run: |
|
||||||
|
|
|
||||||
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
|
|
@ -10,8 +10,8 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Install Aftman
|
- name: Install Rokit
|
||||||
uses: ok-nick/setup-aftman@v0.4.2
|
uses: CompeyDev/setup-rokit@v0.1.2
|
||||||
|
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
run: wally install
|
run: wally install
|
||||||
|
|
|
||||||
11
aftman.toml
11
aftman.toml
|
|
@ -1,11 +0,0 @@
|
||||||
# This file lists tools managed by Aftman, a cross-platform toolchain manager.
|
|
||||||
# For more information, see https://github.com/LPGhatguy/aftman
|
|
||||||
|
|
||||||
# To add a new tool, add an entry to this table.
|
|
||||||
[tools]
|
|
||||||
wally = "UpliftGames/wally@0.3.2"
|
|
||||||
rojo = "rojo-rbx/rojo@7.4.1"
|
|
||||||
wally-package-types = "JohnnyMorganz/wally-package-types@1.3.1"
|
|
||||||
stylua = "johnnymorganz/stylua@0.20.0"
|
|
||||||
selene = "Kampfkarren/selene@0.26.1"
|
|
||||||
luau-lsp = "johnnymorganz/luau-lsp@1.27.1"
|
|
||||||
12
rokit.toml
Normal file
12
rokit.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
# This file lists tools managed by Rokit, a toolchain manager for Roblox projects.
|
||||||
|
# For more information, see https://github.com/rojo-rbx/rokit
|
||||||
|
|
||||||
|
# New tools can be added by running `rokit add <tool>` in a terminal.
|
||||||
|
|
||||||
|
[tools]
|
||||||
|
wally = "UpliftGames/wally@0.3.2"
|
||||||
|
rojo = "rojo-rbx/rojo@7.4.4"
|
||||||
|
wally-package-types = "JohnnyMorganz/wally-package-types@1.3.2"
|
||||||
|
stylua = "johnnymorganz/stylua@0.20.0"
|
||||||
|
selene = "Kampfkarren/selene@0.27.1"
|
||||||
|
luau-lsp = "johnnymorganz/luau-lsp@1.32.4"
|
||||||
5
src/index.d.ts
vendored
5
src/index.d.ts
vendored
|
|
@ -290,6 +290,11 @@ declare namespace Charm {
|
||||||
* The atoms to synchronize with the server.
|
* The atoms to synchronize with the server.
|
||||||
*/
|
*/
|
||||||
atoms: Atoms;
|
atoms: Atoms;
|
||||||
|
/**
|
||||||
|
* Whether to ignore patches sent before the client has been hydrated.
|
||||||
|
* Defaults to `true`.
|
||||||
|
*/
|
||||||
|
ignoreUnhydrated?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ServerOptions<Molecules extends MoleculeMap> {
|
interface ServerOptions<Molecules extends MoleculeMap> {
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,11 @@ type ClientOptions = {
|
||||||
The atoms to synchronize with the server.
|
The atoms to synchronize with the server.
|
||||||
]=]
|
]=]
|
||||||
atoms: { [string]: Atom<any> },
|
atoms: { [string]: Atom<any> },
|
||||||
|
--[=[
|
||||||
|
Whether to ignore patches sent before the client has been hydrated.
|
||||||
|
Default is `true`.
|
||||||
|
]=]
|
||||||
|
ignoreUnhydrated: boolean?,
|
||||||
}
|
}
|
||||||
|
|
||||||
type ClientSyncer = {
|
type ClientSyncer = {
|
||||||
|
|
@ -30,12 +35,22 @@ type ClientSyncer = {
|
||||||
]=]
|
]=]
|
||||||
local function client(options: ClientOptions): ClientSyncer
|
local function client(options: ClientOptions): ClientSyncer
|
||||||
local atoms = options.atoms
|
local atoms = options.atoms
|
||||||
|
local ignoreUnhydrated = options.ignoreUnhydrated ~= false
|
||||||
local self = {} :: ClientSyncer
|
local self = {} :: ClientSyncer
|
||||||
|
local hydrated = false
|
||||||
|
|
||||||
-- Apply the state changes sent by the server.
|
-- Apply the state changes sent by the server.
|
||||||
function self:sync(...)
|
function self:sync(...)
|
||||||
for index = 1, select("#", ...) do
|
for index = 1, select("#", ...) do
|
||||||
local payload = select(index, ...)
|
local payload: SyncPayload = select(index, ...)
|
||||||
|
|
||||||
|
if ignoreUnhydrated and payload.type == "patch" and not hydrated then
|
||||||
|
-- If the client is not initialized, ignore patches. This is
|
||||||
|
-- to prevent patching incomplete state.
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
|
||||||
|
hydrated = true
|
||||||
|
|
||||||
store.batch(function()
|
store.batch(function()
|
||||||
for key, state in next, payload.data do
|
for key, state in next, payload.data do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue