From f4ff1ff3a9e170db7bef357cab5e5de392d1a9b8 Mon Sep 17 00:00:00 2001 From: heoblitz Date: Mon, 25 Sep 2023 14:13:39 +0900 Subject: [PATCH 1/3] Revert "Avoids under-observing routes state in binding" This reverts commit 865ef58e8f0ee4dc70c28b22174ffac7adf02e23. --- Sources/TCACoordinators/TCARouter/TCARouter.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/TCACoordinators/TCARouter/TCARouter.swift b/Sources/TCACoordinators/TCARouter/TCARouter.swift index 07430bd..2f9b9a5 100644 --- a/Sources/TCACoordinators/TCARouter/TCARouter.swift +++ b/Sources/TCACoordinators/TCARouter/TCARouter.swift @@ -58,7 +58,7 @@ public struct TCARouter< self.action = action self.identifier = identifier self.screenContent = screenContent - viewStore = ViewStore(store, observe: { $0 }) + self.viewStore = ViewStore(store, observe: { $0 }, removeDuplicates: { routes($0).map(\.style) == routes($1).map(\.style) }) } } From b12ba12a7f17743509ceb0a7eee99c56240f47fc Mon Sep 17 00:00:00 2001 From: heoblitz Date: Tue, 26 Sep 2023 13:33:27 +0900 Subject: [PATCH 2/3] Fix observing stale state [description] [issue-number] --- Sources/TCACoordinators/TCARouter/TCARouter.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/TCACoordinators/TCARouter/TCARouter.swift b/Sources/TCACoordinators/TCARouter/TCARouter.swift index 2f9b9a5..e9604fc 100644 --- a/Sources/TCACoordinators/TCARouter/TCARouter.swift +++ b/Sources/TCACoordinators/TCARouter/TCARouter.swift @@ -17,10 +17,10 @@ public struct TCARouter< let updateRoutes: ([Route]) -> CoordinatorAction let action: (ID, ScreenAction) -> CoordinatorAction let identifier: (Screen, Int) -> ID - + @ObservedObject private var viewStore: ViewStore @ViewBuilder var screenContent: (Store) -> ScreenContent - + func scopedStore(index: Int, screen: Screen) -> Store { var screen = screen return store.scope( @@ -34,16 +34,16 @@ public struct TCARouter< } ) } - + public var body: some View { Router( - viewStore.binding(get: routes, send: updateRoutes), + viewStore.binding(get: { _ in store.withState(routes) }, send: updateRoutes), buildView: { screen, index in screenContent(scopedStore(index: index, screen: screen)) } ) } - + public init( store: Store, routes: @escaping (CoordinatorState) -> [Route], From c13f9984e8f7f7123ecc0e86c29f0683bb7e9df6 Mon Sep 17 00:00:00 2001 From: johnpatrickmorgan Date: Wed, 27 Sep 2023 10:32:49 +0100 Subject: [PATCH 3/3] Ensures binding always has latest state Fixes an issue where navigating back after a state change could reset the previous screen to its state before pushing. --- Sources/TCACoordinators/TCARouter/TCARouter.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/TCACoordinators/TCARouter/TCARouter.swift b/Sources/TCACoordinators/TCARouter/TCARouter.swift index e9604fc..900bef8 100644 --- a/Sources/TCACoordinators/TCARouter/TCARouter.swift +++ b/Sources/TCACoordinators/TCARouter/TCARouter.swift @@ -17,10 +17,10 @@ public struct TCARouter< let updateRoutes: ([Route]) -> CoordinatorAction let action: (ID, ScreenAction) -> CoordinatorAction let identifier: (Screen, Int) -> ID - + @ObservedObject private var viewStore: ViewStore @ViewBuilder var screenContent: (Store) -> ScreenContent - + func scopedStore(index: Int, screen: Screen) -> Store { var screen = screen return store.scope( @@ -34,16 +34,16 @@ public struct TCARouter< } ) } - + public var body: some View { Router( - viewStore.binding(get: { _ in store.withState(routes) }, send: updateRoutes), + ViewStore(store, observe: { $0 }).binding(get: routes, send: updateRoutes), buildView: { screen, index in screenContent(scopedStore(index: index, screen: screen)) } ) } - + public init( store: Store, routes: @escaping (CoordinatorState) -> [Route],