From 7d2c96a7788e0d70812fb1c831483d6c72b0ad12 Mon Sep 17 00:00:00 2001 From: Red Davis Date: Fri, 10 Jun 2022 17:21:35 +0100 Subject: [PATCH] Remove duplicates when propagating state (#31) --- RedUx/Source/Store.swift | 3 ++- RedUx/Source/SwiftUI/UnwrapStore.swift | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/RedUx/Source/Store.swift b/RedUx/Source/Store.swift index 4ab76fc..e3a579c 100644 --- a/RedUx/Source/Store.swift +++ b/RedUx/Source/Store.swift @@ -7,7 +7,7 @@ import SwiftUI /// Generally an application will have one store and then use the scope function to create sub stores for /// different components of the app. @MainActor -public final class Store { +public final class Store where State: Equatable { /// The state of the store. public private(set) var state: State { didSet { @@ -153,6 +153,7 @@ extension Store { // Propagate changes to state to scoped store. scopedStore.parentStatePropagationTask = self.stateSequence + .removeDuplicates() .sink(priority: .high) { [weak scopedStore] in scopedStore?.state = toScopedState($0) } diff --git a/RedUx/Source/SwiftUI/UnwrapStore.swift b/RedUx/Source/SwiftUI/UnwrapStore.swift index 8318878..d5e6a74 100644 --- a/RedUx/Source/SwiftUI/UnwrapStore.swift +++ b/RedUx/Source/SwiftUI/UnwrapStore.swift @@ -1,7 +1,8 @@ import SwiftUI @MainActor -public struct UnwrapStore: View where Content: View { +public struct UnwrapStore: View +where Content: View, State: Equatable { private let content: (Store) -> Content private let store: Store