private fun historyStateReducer( state: HistoryMetadataGroupFragmentState, action: HistoryMetadataGroupFragmentAction, ): HistoryMetadataGroupFragmentState { return when (action) { is HistoryMetadataGroupFragmentAction.UpdateHistoryItems -> state.copy(items = action.items) is HistoryMetadataGroupFragmentAction.Select -> state.copy( items = state.items.toMutableList() .map { if (it == action.item) { it.copy(selected = true) } else { it } }, ) is HistoryMetadataGroupFragmentAction.Deselect -> state.copy( items = state.items.toMutableList() .map { if (it == action.item) { it.copy(selected = false) } else { it } }, ) is HistoryMetadataGroupFragmentAction.DeselectAll -> state.copy( items = state.items.toMutableList() .map { it.copy(selected = false) }, ) is HistoryMetadataGroupFragmentAction.Delete -> { val items = state.items.toMutableList() items.remove(action.item) state.copy(items = items) } is HistoryMetadataGroupFragmentAction.DeleteAll -> state.copy(items = emptyList()) is HistoryMetadataGroupFragmentAction.UpdatePendingDeletionItems -> state.copy(pendingDeletionItems = action.pendingDeletionItems) is HistoryMetadataGroupFragmentAction.ChangeEmptyState -> state.copy( isEmpty = action.isEmpty, ) }
Reduces the history metadata state from the current state with the provided [action] to be performed.