diff --git a/src/__tests__/sync/validate.spec.luau b/src/__tests__/sync/validate.spec.luau index 2d562b2..68d9bfd 100644 --- a/src/__tests__/sync/validate.spec.luau +++ b/src/__tests__/sync/validate.spec.luau @@ -18,7 +18,7 @@ return function() nested_atom = { value = atom(0), expected = false }, } - for key, case in cases do + for key, case in next, cases do local success, result = pcall(function() validate(case.value, key) end) diff --git a/src/atom.luau b/src/atom.luau index fc6bf64..07aeb59 100644 --- a/src/atom.luau +++ b/src/atom.luau @@ -15,7 +15,7 @@ local function atom(state: T, options: AtomOptions?): Atom local function atom(...) if select("#", ...) == 0 then - for set in store.capturing do + for set in next, store.capturing do set[atom] = true end diff --git a/src/mapped.luau b/src/mapped.luau index 2df2305..c7a2496 100644 --- a/src/mapped.luau +++ b/src/mapped.luau @@ -36,7 +36,7 @@ local function mapped(molecule: Molecule<{ [K0]: V0 }>, mapper: local mappedKeys = {} -- TODO: Only call mapper if the item has changed. - for key, item in items do + for key, item in next, items do local newItem, newKey = mapper(item, key) if newKey == nil then newKey = key :: any @@ -48,7 +48,7 @@ local function mapped(molecule: Molecule<{ [K0]: V0 }>, mapper: end end - for key in prevMappedItems do + for key in next, prevMappedItems do if mappedKeys[key] == nil and mappedItems[key] == prevMappedItems[key] then mappedItems[key] = nil end diff --git a/src/sync/client.luau b/src/sync/client.luau index da20e0c..fa214dd 100644 --- a/src/sync/client.luau +++ b/src/sync/client.luau @@ -36,7 +36,7 @@ local function client(options: ClientOptions): ClientSyncer for index = 1, select("#", ...) do local payload = select(index, ...) - for key, state in payload.data do + for key, state in next, payload.data do if payload.type == "patch" then atoms[key](patch.apply(atoms[key](), state)) else diff --git a/src/sync/patch.luau b/src/sync/patch.luau index c06ad2b..c59b166 100644 --- a/src/sync/patch.luau +++ b/src/sync/patch.luau @@ -13,7 +13,7 @@ end local function diff(prevState: { [any]: any }, nextState: { [any]: any }) local patches = table.clone(nextState) - for key, previous in prevState do + for key, previous in next, prevState do local next = nextState[key] if previous == next then @@ -26,7 +26,7 @@ local function diff(prevState: { [any]: any }, nextState: { [any]: any }) end if _G.__DEV__ then - for key, value in prevState do + for key, value in next, prevState do validate(value, key) end @@ -50,7 +50,7 @@ local function apply(state: any, patches: any): any local nextState = table.clone(state) local stateIsArray = state[1] ~= nil - for key, patch in patches do + for key, patch in next, patches do -- Diff-checking an array produces a sparse array, which will not be -- preserved when converted to JSON. To prevent this, we turn string -- keys back into numeric keys. diff --git a/src/sync/server.luau b/src/sync/server.luau index 96e6273..e13a4dc 100644 --- a/src/sync/server.luau +++ b/src/sync/server.luau @@ -72,7 +72,7 @@ local function server(options: ServerOptions): ServerSyncer local function getSnapshot() local snapshot: { [string]: any } = {} - for key, atom in options.atoms do + for key, atom in next, options.atoms do snapshot[key] = atom() end return snapshot @@ -105,7 +105,7 @@ local function server(options: ServerOptions): ServerSyncer -- Populate the initial state and snapshot for each atom. -- Subscribe to each atom and update the state when it changes. - for key, atom in options.atoms do + for key, atom in next, options.atoms do cleanups[key] = subscribe(atom, function(current, previous) pushSnapshot(key, current, previous) changed = true @@ -122,7 +122,7 @@ local function server(options: ServerOptions): ServerSyncer local payloads: { SyncPayload } = {} local lastSnapshot - for index, snapshot in snapshots do + for index, snapshot in next, snapshots do lastSnapshot = snapshot if index == 1 then @@ -138,14 +138,14 @@ local function server(options: ServerOptions): ServerSyncer snapshots = { lastSnapshot } changed = false - for _, player in Players:GetPlayers() do + for _, player in next, Players:GetPlayers() do callback(player, unpack(payloads)) end end, options.interval or 0) return function() disconnect() - for _, cleanup in cleanups do + for _, cleanup in next, cleanups do cleanup() end end @@ -170,7 +170,7 @@ local function server(options: ServerOptions): ServerSyncer local payloads: { SyncPayload } = {} - for index, snapshot in snapshots do + for index, snapshot in next, snapshots do if index == 1 then continue end diff --git a/src/sync/validate.luau b/src/sync/validate.luau index 364a1cd..ffbcec6 100644 --- a/src/sync/validate.luau +++ b/src/sync/validate.luau @@ -8,7 +8,7 @@ local function isUnsafeTable(object: { [any]: any }) local objectSize = 0 -- All keys must have the same type - for key in object do + for key in next, object do local currentType = type(key) if not keyType and SAFE_KEYS[currentType] then