commit b38075dd275d9565e2d1509aecbcbd859ebfc663 parent e3a00b85356850d1f31954ba40f9b35eb239f119 Author: pollymce <pmceldowney@mozilla.com> Date: Mon, 17 Nov 2025 13:45:14 +0000 Bug 1980350 - get rid of UIStore. r=android-reviewers,sfamisa This was just a passthrough following the work done in bug 1980348 Differential Revision: https://phabricator.services.mozilla.com/D272130 Diffstat:
20 files changed, 38 insertions(+), 172 deletions(-)
diff --git a/mobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/store/BrowserToolbarStore.kt b/mobile/android/android-components/components/compose/browser-toolbar/src/main/java/mozilla/components/compose/browser/toolbar/store/BrowserToolbarStore.kt @@ -14,15 +14,15 @@ import mozilla.components.compose.browser.toolbar.store.BrowserEditToolbarAction import mozilla.components.compose.browser.toolbar.store.BrowserToolbarInteraction.BrowserToolbarEvent import mozilla.components.compose.browser.toolbar.ui.BrowserToolbarQuery import mozilla.components.lib.state.Middleware -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store /** - * [UiStore] for maintaining the state of the browser toolbar. + * [Store] for maintaining the state of the browser toolbar. */ open class BrowserToolbarStore( initialState: BrowserToolbarState = BrowserToolbarState(), middleware: List<Middleware<BrowserToolbarState, BrowserToolbarAction>> = emptyList(), -) : UiStore<BrowserToolbarState, BrowserToolbarAction>( +) : Store<BrowserToolbarState, BrowserToolbarAction>( initialState = initialState, reducer = ::reduce, middleware = middleware, diff --git a/mobile/android/android-components/components/lib/state/src/main/java/mozilla/components/lib/state/UiStore.kt b/mobile/android/android-components/components/lib/state/src/main/java/mozilla/components/lib/state/UiStore.kt @@ -1,28 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package mozilla.components.lib.state - -import androidx.annotation.MainThread - -/** - * A generic store holding an immutable [State] that will always run on the Main thread. - * - * The [State] can only be modified by dispatching [Action]s which will create a new state and notify all registered - * [Observer]s. - * - * @param initialState The initial state until a dispatched [Action] creates a new state. - * @param reducer A function that gets the current [State] and [Action] passed in and will return a new [State]. - * @param middleware Optional list of [Middleware] sitting between the [Store] and the [Reducer]. - */ -@MainThread -open class UiStore<S : State, A : Action>( - initialState: S, - reducer: Reducer<S, A>, - middleware: List<Middleware<S, A>> = emptyList(), -) : Store<S, A>( - initialState, - reducer, - middleware, -) diff --git a/mobile/android/android-components/components/lib/state/src/test/java/mozilla/components/lib/state/UiStoreTest.kt b/mobile/android/android-components/components/lib/state/src/test/java/mozilla/components/lib/state/UiStoreTest.kt @@ -1,102 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package mozilla.components.lib.state - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import mozilla.components.support.test.rule.MainCoroutineRule -import mozilla.components.support.test.rule.runTestOnMain -import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith -import java.io.IOException - -/** - * The tests here are largely identical to those in [StoreTest], however, these run using [AndroidJUnit4] - * so that we can run them with a [UiStore] on the main thread with [runTestOnMain]. - * - * The only new test that is added here is [UiStoreTest.Dispatching on a non-UI dispatcher will throw an exception]. - */ -@RunWith(AndroidJUnit4::class) -class UiStoreTest { - - @get:Rule - val coroutineTestRule = MainCoroutineRule() - - @Test - fun `Dispatching Action executes reducers and creates new State`() { - val store = UiStore( - TestState(counter = 23), - ::reducer, - ) - - store.dispatch(TestAction.IncrementAction) - - assertEquals(24, store.state.counter) - - store.dispatch(TestAction.DecrementAction) - store.dispatch(TestAction.DecrementAction) - - assertEquals(22, store.state.counter) - } - - @Test - fun `Observer gets notified about state changes`() { - val store = UiStore( - TestState(counter = 23), - ::reducer, - ) - - var observedValue = 0 - - store.observeManually { state -> observedValue = state.counter }.also { - it.resume() - } - - store.dispatch(TestAction.IncrementAction) - - assertEquals(24, observedValue) - } - - @Test - fun `Observer gets initial value before state changes`() { - val store = UiStore( - TestState(counter = 23), - ::reducer, - ) - - var observedValue = 0 - - store.observeManually { state -> observedValue = state.counter }.also { - it.resume() - } - - assertEquals(23, observedValue) - } - - @Test - fun `Middleware can catch exceptions in reducer`() = runTestOnMain { - var caughtException: Exception? = null - - val catchingMiddleware: Middleware<TestState, TestAction> = { _, next, action -> - try { - next(action) - } catch (e: Exception) { - caughtException = e - } - } - - val store = UiStore( - TestState(counter = 0), - { _: State, _: Action -> throw IOException() }, - listOf(catchingMiddleware), - ) - - store.dispatch(TestAction.IncrementAction) - - assertTrue(caughtException is IOException) - } -} diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/bookmarks/BookmarksStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/bookmarks/BookmarksStore.kt @@ -8,7 +8,7 @@ import android.content.Context import androidx.navigation.NavController import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.Reducer -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store import org.mozilla.fenix.HomeActivity /** @@ -42,7 +42,7 @@ internal class BookmarksStore( middleware: List<Middleware<BookmarksState, BookmarksAction>> = listOf(), val lifecycleHolder: LifecycleHolder? = null, bookmarkToLoad: String? = null, -) : UiStore<BookmarksState, BookmarksAction>( +) : Store<BookmarksState, BookmarksAction>( initialState = initialState, reducer = reducer, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/browser/store/BrowserScreenStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/browser/store/BrowserScreenStore.kt @@ -8,7 +8,7 @@ import android.content.Context import androidx.fragment.app.FragmentManager import androidx.lifecycle.LifecycleOwner import mozilla.components.lib.state.Middleware -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store import org.mozilla.fenix.browser.store.BrowserScreenAction.CancelPrivateDownloadsOnPrivateTabsClosedAccepted import org.mozilla.fenix.browser.store.BrowserScreenAction.ClosingLastPrivateTab import org.mozilla.fenix.browser.store.BrowserScreenAction.CustomTabColorsUpdated @@ -18,7 +18,7 @@ import org.mozilla.fenix.browser.store.BrowserScreenAction.PageTranslationStatus import org.mozilla.fenix.browser.store.BrowserScreenAction.ReaderModeStatusUpdated /** - * [UiStore] for the browser screen. + * [Store] for the browser screen. * * @param initialState The initial state of the store. * @param middleware The middlewares to be applied to this store. @@ -26,7 +26,7 @@ import org.mozilla.fenix.browser.store.BrowserScreenAction.ReaderModeStatusUpdat class BrowserScreenStore( initialState: BrowserScreenState = BrowserScreenState(), middleware: List<Middleware<BrowserScreenState, BrowserScreenAction>> = emptyList(), -) : UiStore<BrowserScreenState, BrowserScreenAction>( +) : Store<BrowserScreenState, BrowserScreenAction>( initialState = initialState, reducer = ::reduce, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/store/MenuStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/menu/store/MenuStore.kt @@ -7,7 +7,6 @@ package org.mozilla.fenix.components.menu.store import androidx.annotation.VisibleForTesting import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.Store -import mozilla.components.lib.state.UiStore /** * The [Store] for holding the [MenuState] and applying [MenuAction]s. @@ -15,7 +14,7 @@ import mozilla.components.lib.state.UiStore class MenuStore( initialState: MenuState, middleware: List<Middleware<MenuState, MenuAction>> = listOf(), -) : UiStore<MenuState, MenuAction>( +) : Store<MenuState, MenuAction>( initialState = initialState, reducer = ::reducer, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/cfrs/CfrToolsStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/cfrs/CfrToolsStore.kt @@ -7,7 +7,7 @@ package org.mozilla.fenix.debugsettings.cfrs import mozilla.components.lib.state.Action import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.State -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store /** * Value type that represents the state of the CFR Tools. @@ -144,13 +144,13 @@ internal object CfrToolsReducer { } /** - * A [UiStore] that holds the [CfrToolsState] for the CFR Tools and reduces [CfrToolsAction]s + * A [Store] that holds the [CfrToolsState] for the CFR Tools and reduces [CfrToolsAction]s * dispatched to the store. */ class CfrToolsStore( initialState: CfrToolsState = CfrToolsState(), middlewares: List<Middleware<CfrToolsState, CfrToolsAction>> = emptyList(), -) : UiStore<CfrToolsState, CfrToolsAction>( +) : Store<CfrToolsState, CfrToolsAction>( initialState, CfrToolsReducer::reduce, middlewares, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/gleandebugtools/GleanDebugToolsStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/debugsettings/gleandebugtools/GleanDebugToolsStore.kt @@ -7,7 +7,7 @@ package org.mozilla.fenix.debugsettings.gleandebugtools import mozilla.components.lib.state.Action import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.State -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store /** * Value type that represents the state of the Glean Debug Tools. @@ -101,13 +101,13 @@ internal object GleanDebugToolsReducer { } /** - * A [UiStore] that holds the [GleanDebugToolsState] for the Glean Debug Tools and reduces + * A [Store] that holds the [GleanDebugToolsState] for the Glean Debug Tools and reduces * [GleanDebugToolsAction]s dispatched to the store. */ class GleanDebugToolsStore( initialState: GleanDebugToolsState, middlewares: List<Middleware<GleanDebugToolsState, GleanDebugToolsAction>> = emptyList(), -) : UiStore<GleanDebugToolsState, GleanDebugToolsAction>( +) : Store<GleanDebugToolsState, GleanDebugToolsAction>( initialState, GleanDebugToolsReducer::reduce, middlewares, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/downloads/listscreen/store/DownloadUIStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/downloads/listscreen/store/DownloadUIStore.kt @@ -6,7 +6,6 @@ package org.mozilla.fenix.downloads.listscreen.store import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.Store -import mozilla.components.lib.state.UiStore import org.mozilla.fenix.downloads.listscreen.store.DownloadUIState.Mode /** @@ -15,7 +14,7 @@ import org.mozilla.fenix.downloads.listscreen.store.DownloadUIState.Mode class DownloadUIStore( initialState: DownloadUIState, middleware: List<Middleware<DownloadUIState, DownloadUIAction>> = emptyList(), -) : UiStore<DownloadUIState, DownloadUIAction>( +) : Store<DownloadUIState, DownloadUIAction>( initialState = initialState, reducer = ::downloadStateReducer, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/onboarding/store/PrivacyPreferencesStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/onboarding/store/PrivacyPreferencesStore.kt @@ -7,7 +7,7 @@ package org.mozilla.fenix.onboarding.store import mozilla.components.lib.state.Action import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.State -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store /** * Represents the state of privacy preferences. @@ -78,13 +78,13 @@ internal object PrivacyPreferencesReducer { } /** - * A [UiStore] that holds the [PrivacyPreferencesState] for the privacy preferences and reduces + * A [Store] that holds the [PrivacyPreferencesState] for the privacy preferences and reduces * [PrivacyPreferencesAction]s dispatched to the store. */ class PrivacyPreferencesStore( initialState: PrivacyPreferencesState = PrivacyPreferencesState(), middlewares: List<Middleware<PrivacyPreferencesState, PrivacyPreferencesAction>> = emptyList(), -) : UiStore<PrivacyPreferencesState, PrivacyPreferencesAction>( +) : Store<PrivacyPreferencesState, PrivacyPreferencesAction>( initialState, PrivacyPreferencesReducer::reduce, middlewares, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/reviewprompt/CustomReviewPromptState.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/reviewprompt/CustomReviewPromptState.kt @@ -9,14 +9,13 @@ import mozilla.components.lib.state.Action import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.State import mozilla.components.lib.state.Store -import mozilla.components.lib.state.UiStore import org.mozilla.fenix.reviewprompt.ui.CustomReviewPrompt /** [Store] for holding [CustomReviewPromptState] and applying [CustomReviewPromptAction]s. */ class CustomReviewPromptStore( initialState: CustomReviewPromptState, middleware: List<Middleware<CustomReviewPromptState, CustomReviewPromptAction>> = emptyList(), -) : UiStore<CustomReviewPromptState, CustomReviewPromptAction>( +) : Store<CustomReviewPromptState, CustomReviewPromptAction>( initialState = initialState, reducer = ::reduceCustomReviewPromptActions, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/search/SearchFragmentStore.kt @@ -19,7 +19,6 @@ import mozilla.components.lib.state.Action import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.State import mozilla.components.lib.state.Store -import mozilla.components.lib.state.UiStore import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.automotive.isAndroidAutomotiveAvailable import org.mozilla.fenix.browser.browsingmode.BrowsingMode @@ -39,7 +38,7 @@ import org.mozilla.fenix.utils.Settings class SearchFragmentStore( initialState: SearchFragmentState, middleware: List<Middleware<SearchFragmentState, SearchFragmentAction>> = emptyList(), -) : UiStore<SearchFragmentState, SearchFragmentAction>( +) : Store<SearchFragmentState, SearchFragmentAction>( initialState = initialState, reducer = ::searchStateReducer, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/address/store/AddressStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/address/store/AddressStore.kt @@ -5,7 +5,7 @@ package org.mozilla.fenix.settings.address.store import mozilla.components.lib.state.Middleware -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store /** * A Store for handling [AddressState] and dispatching [AddressAction]. @@ -16,4 +16,4 @@ import mozilla.components.lib.state.UiStore class AddressStore( initialState: AddressState, middleware: List<Middleware<AddressState, AddressAction>>, -) : UiStore<AddressState, AddressAction>(initialState, ::addressReducer, middleware) +) : Store<AddressState, AddressAction>(initialState, ::addressReducer, middleware) diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/biometric/ui/state/SecureScreenStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/biometric/ui/state/SecureScreenStore.kt @@ -5,7 +5,7 @@ package org.mozilla.fenix.settings.biometric.ui.state import mozilla.components.lib.state.Reducer -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store /** * The store for the secure screen. @@ -16,7 +16,7 @@ import mozilla.components.lib.state.UiStore class SecureScreenStore( initialState: SecureScreenState = SecureScreenState.Initial, reducer: Reducer<SecureScreenState, SecureScreenAction> = ::secureScreenReducer, -) : UiStore<SecureScreenState, SecureScreenAction>( +) : Store<SecureScreenState, SecureScreenAction>( initialState = initialState, reducer = reducer, middleware = emptyList(), diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/datachoices/DataChoicesStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/datachoices/DataChoicesStore.kt @@ -6,13 +6,13 @@ package org.mozilla.fenix.settings.datachoices import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.Reducer -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store internal class DataChoicesStore( initialState: DataChoicesState, reducer: Reducer<DataChoicesState, DataChoicesAction> = ::dataChoicesReducer, middleware: List<Middleware<DataChoicesState, DataChoicesAction>> = listOf(), -) : UiStore<DataChoicesState, DataChoicesAction>( +) : Store<DataChoicesState, DataChoicesAction>( initialState = initialState, reducer = reducer, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/doh/DohSettingsStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/doh/DohSettingsStore.kt @@ -7,7 +7,7 @@ package org.mozilla.fenix.settings.doh import androidx.navigation.NavController import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.Reducer -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store import org.mozilla.fenix.HomeActivity /** @@ -42,7 +42,7 @@ internal class DohSettingsStore( reducer: Reducer<DohSettingsState, DohSettingsAction> = ::dohSettingsReducer, middleware: List<Middleware<DohSettingsState, DohSettingsAction>> = listOf(), var lifecycleHolder: LifecycleHolder? = null, -) : UiStore<DohSettingsState, DohSettingsAction>( +) : Store<DohSettingsState, DohSettingsAction>( initialState = initialState, reducer = reducer, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/logins/ui/LoginsStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/logins/ui/LoginsStore.kt @@ -6,7 +6,7 @@ package org.mozilla.fenix.settings.logins.ui import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.Reducer -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store import org.mozilla.fenix.lifecycle.LifecycleHolder /** @@ -22,7 +22,7 @@ internal class LoginsStore( reducer: Reducer<LoginsState, LoginsAction> = ::loginsReducer, middleware: List<Middleware<LoginsState, LoginsAction>> = listOf(), val lifecycleHolder: LifecycleHolder? = null, -) : UiStore<LoginsState, LoginsAction>( +) : Store<LoginsState, LoginsAction>( initialState = initialState, reducer = reducer, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/SettingsSearchStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/settings/settingssearch/SettingsSearchStore.kt @@ -6,7 +6,7 @@ package org.mozilla.fenix.settings.settingssearch import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.State -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store /** * Store for the settings search screen. @@ -17,7 +17,7 @@ import mozilla.components.lib.state.UiStore class SettingsSearchStore( initialState: SettingsSearchState = SettingsSearchState.Default(emptyList()), middleware: List<Middleware<SettingsSearchState, SettingsSearchAction>> = emptyList(), -) : UiStore<SettingsSearchState, SettingsSearchAction>( +) : Store<SettingsSearchState, SettingsSearchAction>( initialState = initialState, reducer = ::reduce, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/startupCrash/StartupCrashStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/startupCrash/StartupCrashStore.kt @@ -6,13 +6,13 @@ package org.mozilla.fenix.startupCrash import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.Reducer -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store internal class StartupCrashStore( initialState: StartupCrashState, reducer: Reducer<StartupCrashState, StartupCrashAction> = ::startupCrashReducer, middleware: List<Middleware<StartupCrashState, StartupCrashAction>> = listOf(), -) : UiStore<StartupCrashState, StartupCrashAction>( +) : Store<StartupCrashState, StartupCrashAction>( initialState = initialState, reducer = reducer, middleware = middleware, diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/webcompat/store/WebCompatReporterStore.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/webcompat/store/WebCompatReporterStore.kt @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.asSharedFlow import mozilla.components.lib.state.Action import mozilla.components.lib.state.Middleware import mozilla.components.lib.state.State -import mozilla.components.lib.state.UiStore +import mozilla.components.lib.state.Store import org.mozilla.fenix.R /** @@ -212,13 +212,13 @@ private fun reduce( } /** - * A [UiStore] that holds the [WebCompatReporterState] for the WebCompat Reporter and reduces + * A [Store] that holds the [WebCompatReporterState] for the WebCompat Reporter and reduces * [WebCompatReporterAction]s dispatched to the store. */ class WebCompatReporterStore( initialState: WebCompatReporterState = WebCompatReporterState(), middleware: List<Middleware<WebCompatReporterState, WebCompatReporterAction>> = listOf(), -) : UiStore<WebCompatReporterState, WebCompatReporterAction>( +) : Store<WebCompatReporterState, WebCompatReporterAction>( initialState, ::reduce, middleware,