fun protectionsStateReducer( state: ProtectionsState, action: ProtectionsAction, ): ProtectionsState { return when (action) { is ProtectionsAction.Change -> state.copy( url = action.url, isTrackingProtectionEnabled = action.isTrackingProtectionEnabled, isCookieBannerHandlingEnabled = action.isCookieBannerHandlingEnabled, listTrackers = action.listTrackers, mode = action.mode, ) is ProtectionsAction.UrlChange -> state.copy( url = action.url, ) is ProtectionsAction.TrackerLogChange -> state.copy(listTrackers = action.listTrackers) ProtectionsAction.ExitDetailsMode -> state.copy( mode = ProtectionsState.Mode.Normal, ) is ProtectionsAction.EnterDetailsMode -> state.copy( mode = ProtectionsState.Mode.Details( action.category, action.categoryBlocked, ), lastAccessedCategory = action.category.name, ) is ProtectionsAction.ToggleCookieBannerHandlingProtectionEnabled -> state.copy( isCookieBannerHandlingEnabled = action.isEnabled, ) }
The [ProtectionsState] reducer.