internal object TabsTrayReducer { fun reduce(state: TabsTrayState, action: TabsTrayAction): TabsTrayState { return when (action) { is TabsTrayAction.EnterSelectMode -> state.copy(mode = TabsTrayState.Mode.Select(emptySet())) is TabsTrayAction.ExitSelectMode -> state.copy(mode = TabsTrayState.Mode.Normal) is TabsTrayAction.AddSelectTab -> state.copy(mode = TabsTrayState.Mode.Select(state.mode.selectedTabs + action.tab)) is TabsTrayAction.RemoveSelectTab -> { val selected = state.mode.selectedTabs.filter { it.id != action.tab.id }.toSet() state.copy( mode = if (selected.isEmpty()) { TabsTrayState.Mode.Normal } else { TabsTrayState.Mode.Select(selected) }, ) } is TabsTrayAction.PageSelected -> state.copy(selectedPage = action.page) is TabsTrayAction.SyncNow -> state.copy(syncing = true) is TabsTrayAction.SyncCompleted -> state.copy(syncing = false) is TabsTrayAction.UpdateInactiveTabs -> state.copy(inactiveTabs = action.tabs) is TabsTrayAction.UpdateNormalTabs -> state.copy(normalTabs = action.tabs) is TabsTrayAction.UpdatePrivateTabs -> state.copy(privateTabs = action.tabs) is TabsTrayAction.UpdateSyncedTabs -> state.copy(syncedTabs = action.tabs) } } }
Reducer for [TabsTrayStore].