diff --git a/BrowserKit/Sources/Redux/State.swift b/BrowserKit/Sources/Redux/State.swift index 9e2bbc7ea4350..a6a28023482c7 100644 --- a/BrowserKit/Sources/Redux/State.swift +++ b/BrowserKit/Sources/Redux/State.swift @@ -7,7 +7,7 @@ import Foundation /// Defines the entire application state including the UI state and any model state that you used in the app. /// This state is stored inside of the `Store`, then you have views and other subscribers that will get notified /// every single time that state updates into the entire app. -public protocol StateType: Sendable { +public protocol StateType: Sendable, Equatable { /// Returns a default State by clearing any transient data from previous one. /// /// All the state properties that have a default value into the initializer should be restore to default. diff --git a/BrowserKit/Sources/Redux/Subscription.swift b/BrowserKit/Sources/Redux/Subscription.swift index f7ff3dd0ef761..3e005b5c156b4 100644 --- a/BrowserKit/Sources/Redux/Subscription.swift +++ b/BrowserKit/Sources/Redux/Subscription.swift @@ -5,7 +5,7 @@ import Foundation @MainActor -final class SubscriptionWrapper: @MainActor Hashable { +final class SubscriptionWrapper: @MainActor Hashable { private let originalSubscription: Subscription weak var subscriber: AnyStoreSubscriber? private let objectIdentifier: ObjectIdentifier @@ -43,7 +43,7 @@ final class SubscriptionWrapper: @MainActor Hashable { } @MainActor -public final class Subscription { +public final class Subscription { public var observer: (@MainActor (State?, State) -> Void)? init() {} @@ -55,6 +55,10 @@ public final class Subscription { } func newValues(oldState: State?, newState: State) { + // State was updated but observers are not notified if the state is the same + guard newState != oldState else { + return + } self.observer?(oldState, newState) } diff --git a/firefox-ios/Client/Redux/GlobalState/ActiveScreenState.swift b/firefox-ios/Client/Redux/GlobalState/ActiveScreenState.swift index 508a0d1240564..f699ed6413d82 100644 --- a/firefox-ios/Client/Redux/GlobalState/ActiveScreenState.swift +++ b/firefox-ios/Client/Redux/GlobalState/ActiveScreenState.swift @@ -6,7 +6,7 @@ import Foundation import Redux import Common -enum AppScreenState: Sendable { +enum AppScreenState: Sendable, Equatable { case browserViewController(BrowserViewControllerState) case homepage(HomepageState) case mainMenu(MainMenuState) @@ -100,7 +100,7 @@ enum AppScreenState: Sendable { } } -struct ActiveScreensState: Sendable { +struct ActiveScreensState: Sendable, Equatable { let screens: [AppScreenState] init() {