refactor: use new type solver

This commit is contained in:
littensy 2026-04-02 06:49:54 -07:00
parent 748dbc5014
commit 22b440e35f
32 changed files with 169 additions and 155 deletions

View file

@ -3,7 +3,7 @@ local patch = require("./patch")
local types = require("./types")
type SyncPayload = types.SyncPayload
type ReactiveProxy<T = {}> = types.ReactiveProxy<T>
type ReactiveProxy<T = { [any]: any }> = types.ReactiveProxy<T>
local trackedSignals: { [string]: (any) -> any } = {}
local trackedReactives: { [string]: ReactiveProxy } = {}

View file

@ -39,7 +39,7 @@ end
long as the target array is not sparse. This function ensures that the diff
function produces a patch that can be correctly applied.
]]
local function stringifySparseArray(object: {}): { [string | number]: any }
local function stringifySparseArray(object: { [any]: any }): { [string | number]: any }
local maxn = table.maxn(object)
if maxn == 0 or maxn == #object then

View file

@ -39,8 +39,9 @@ local syncCallback: ((client: any, payloads: { SyncPayload }) -> ())?
support custom implementations of reactive proxies.
]]
local function toRaw<T>(value: T): T
local value: any = value
if type(value) == "table" and type(value.__target) == "table" and type(value.__track) == "function" then
value.__track()
(value.__track :: () -> ())()
return toRaw(value.__target)
end
return value
@ -153,15 +154,17 @@ local function selectFromGlobalPatchList(client: any, globalPatches: { any }): {
local status = clientKeys[key]
if status == LISTENING_FOR_CHANGES then
table.insert(payloads, {
local payload: SyncPayload = {
type = "patch",
data = { [key] = patchData },
})
}
table.insert(payloads, payload)
elseif status == PENDING_INITIAL_STATE then
table.insert(payloads, {
local payload: SyncPayload = {
type = "init",
data = { [key] = update.newValue },
})
}
table.insert(payloads, payload)
clientKeys[key] = LISTENING_FOR_CHANGES
end
end
@ -228,11 +231,19 @@ local function selectFromGlobalPatch(client: any, globalPatch: { [string]: any }
end
if next(initData) ~= nil then
table.insert(payloads, { type = "init", data = initData })
local payload: SyncPayload = {
type = "init",
data = initData,
}
table.insert(payloads, payload)
end
if next(patchData) ~= nil then
table.insert(payloads, { type = "patch", data = patchData })
local payload: SyncPayload = {
type = "patch",
data = patchData,
}
table.insert(payloads, payload)
end
return payloads

View file

@ -2,10 +2,6 @@ local Charm = require("../Charm")
type Atom<T> = Charm.Atom<T>
type NestedTable = {
[any]: NestedTable | any,
}
--[[
Flattens a nested table into a single table with slash-separated keys.
Useful for recursively collecting atoms returned by modules.
@ -13,15 +9,15 @@ type NestedTable = {
@param input A nested table.
@return A flattened table with slash-separated keys.
]]
local function flatten<Flattened>(input: {}): Flattened
local function flatten<Flattened>(input: { [any]: any }): Flattened
local result = {}
local function visit(node: {}, path: string)
local function visit(node: { [any]: any }, path: string)
for key, value in node do
local location = if path == "" then tostring(key) else path .. "/" .. tostring(key)
if type(value) == "table" then
visit(value :: {}, location)
visit(value, location)
else
result[location] = value
end

View file

@ -1,4 +1,4 @@
local function isTableUnsafe(object: {})
local function isTableUnsafe(object: { [any]: any })
local key = next(object)
if key == nil then
@ -31,9 +31,8 @@ end
with remote argument limitations, such as sparse arrays or mixed tables.
@param value The table value.
@param key The key of the value.
]]
local function validate(value: {})
local function validate(value: { [any]: any })
if isTableUnsafe(value) then
warn(
`Cannot sync tables unsupported by remote events! See the table below for more info.\n\n`