diff --git a/src/combineProducers.lua b/src/combineProducers.lua index e7fc5ec..4509169 100644 --- a/src/combineProducers.lua +++ b/src/combineProducers.lua @@ -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 diff --git a/src/utils/createSelectArrayDiffs.lua b/src/utils/createSelectArrayDiffs.lua index 152ec57..9e4d976 100644 --- a/src/utils/createSelectArrayDiffs.lua +++ b/src/utils/createSelectArrayDiffs.lua @@ -37,17 +37,19 @@ local function createSelectArrayDiffs( local deletions: { Entry } = {} local entries: { [unknown]: Entry } = {} - 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