Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/combineProducers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,18 @@ local function combineActions(producers: types.ProducerMap)

for actionName, actions in actionsByName do
combinedActions[actionName] = function(combinedState, ...)
local nextState = table.clone(combinedState)
local nextState

for _, action in actions do
local producerName = producerNamesByAction[action]
local producerState = nextState[producerName]
nextState[producerName] = action(producerState, ...)
local producerState = combinedState[producerName]
local newState = action(producerState, ...)
if newState == producerState then continue end
if not nextState then nextState = table.clone(combinedState) end
nextState[producerName] = newState
end

return nextState
return nextState or combinedState
end
end

Expand Down
18 changes: 10 additions & 8 deletions src/utils/createSelectArrayDiffs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ local function createSelectArrayDiffs<State, K, V>(
local deletions: { Entry<K, V> } = {}
local entries: { [unknown]: Entry<K, V> } = {}

for key, item in items do
local id = if discriminator then discriminator(item, key) else item
local entry = { key = key, value = item, id = id }
if items then
for key, item in items do
local id = if discriminator then discriminator(item, key) else item
local entry = { key = key, value = item, id = id }

assert(id ~= nil, "Discriminator returned a nil value")
assert(id ~= nil, "Discriminator returned a nil value")

if not lastEntries[id] then
table.insert(additions, entry)
end
if not lastEntries[id] then
table.insert(additions, entry)
end

entries[id] = entry
entries[id] = entry
end
end

for id, item in lastEntries do
Expand Down