Skip to content

Commit da205c7

Browse files
authored
Deprecate Store.scope(state:) for view store observe (#2097)
* Deprecate `Store.scope(state:)` for view store `observe` Explicit scoping is most appropriate for transforming domains, which almost always requires an action transform. In the rare case it doesn't, we should prefer an explicit `{ $0 }`. Scoping for the view has been deprecated for awhile for the `observe` parameter when creating view stores, so let's lead folks that direction. * wip * wip
1 parent 89e4f0c commit da205c7

29 files changed

+120
-94
lines changed

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-AlertsAndConfirmationDialogs.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ struct AlertAndConfirmationDialogView: View {
112112
}
113113
.navigationTitle("Alerts & Dialogs")
114114
.alert(
115-
self.store.scope(state: \.alert),
115+
self.store.scope(state: \.alert, action: { $0 }),
116116
dismiss: .alertDismissed
117117
)
118118
.confirmationDialog(
119-
self.store.scope(state: \.confirmationDialog),
119+
self.store.scope(state: \.confirmationDialog, action: { $0 }),
120120
dismiss: .confirmationDialogDismissed
121121
)
122122
}

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-Animations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ struct AnimationsView: View {
139139
Button("Reset") { viewStore.send(.resetButtonTapped) }
140140
.padding([.horizontal, .bottom])
141141
}
142-
.alert(self.store.scope(state: \.alert), dismiss: .alertDismissed)
142+
.alert(self.store.scope(state: \.alert, action: { $0 }), dismiss: .alertDismissed)
143143
.navigationBarTitleDisplayMode(.inline)
144144
}
145145
}

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-SharedState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ struct SharedStateCounterView: View {
218218
}
219219
.padding(.top)
220220
.navigationTitle("Shared State Demo")
221-
.alert(self.store.scope(state: \.alert), dismiss: .alertDismissed)
221+
.alert(self.store.scope(state: \.alert, action: { $0 }), dismiss: .alertDismissed)
222222
}
223223
}
224224
}

Examples/CaseStudies/SwiftUICaseStudies/02-Effects-WebSocket.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ struct WebSocketView: View {
180180
Text("Received messages")
181181
}
182182
}
183-
.alert(self.store.scope(state: \.alert), dismiss: .alertDismissed)
183+
.alert(self.store.scope(state: \.alert, action: { $0 }), dismiss: .alertDismissed)
184184
.navigationTitle("Web Socket")
185185
}
186186
}

Examples/CaseStudies/SwiftUICaseStudies/04-HigherOrderReducers-ReusableFavoriting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct FavoriteButton<ID: Hashable & Sendable>: View {
7777
Image(systemName: "heart")
7878
.symbolVariant(viewStore.isFavorite ? .fill : .none)
7979
}
80-
.alert(self.store.scope(state: \.alert), dismiss: .alertDismissed)
80+
.alert(self.store.scope(state: \.alert, action: { $0 }), dismiss: .alertDismissed)
8181
}
8282
}
8383
}

Examples/SpeechRecognition/SpeechRecognition/SpeechRecognition.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ struct SpeechRecognitionView: View {
141141
}
142142
}
143143
.padding()
144-
.alert(self.store.scope(state: \.alert), dismiss: .authorizationStateAlertDismissed)
144+
.alert(
145+
self.store.scope(state: \.alert, action: { $0 }),
146+
dismiss: .authorizationStateAlertDismissed
147+
)
145148
}
146149
}
147150
}

Examples/TicTacToe/tic-tac-toe/Sources/GameUIKit/GameViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public final class GameViewController: UIViewController {
2929

3030
public init(store: StoreOf<Game>) {
3131
self.store = store
32-
self.viewStore = ViewStore(store.scope(state: ViewState.init))
32+
self.viewStore = ViewStore(store, observe: ViewState.init)
3333
super.init(nibName: nil, bundle: nil)
3434
}
3535

Examples/TicTacToe/tic-tac-toe/Sources/LoginSwiftUI/LoginView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public struct LoginView: View {
9595
.disabled(viewStore.isLoginButtonDisabled)
9696
}
9797
.disabled(viewStore.isFormDisabled)
98-
.alert(self.store.scope(state: \.alert), dismiss: .alertDismissed)
98+
.alert(self.store.scope(state: \.alert, action: { $0 }), dismiss: .alertDismissed)
9999
}
100100
.navigationTitle("Login")
101101
}

Examples/TicTacToe/tic-tac-toe/Sources/LoginUIKit/LoginViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class LoginViewController: UIViewController {
4040

4141
public init(store: StoreOf<Login>) {
4242
self.store = store
43-
self.viewStore = ViewStore(store.scope(state: ViewState.init, action: Login.Action.init))
43+
self.viewStore = ViewStore(store, observe: ViewState.init, send: Login.Action.init)
4444
super.init(nibName: nil, bundle: nil)
4545
}
4646

Examples/TicTacToe/tic-tac-toe/Sources/NewGameUIKit/NewGameViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class NewGameViewController: UIViewController {
3333

3434
public init(store: StoreOf<NewGame>) {
3535
self.store = store
36-
self.viewStore = ViewStore(store.scope(state: ViewState.init, action: NewGame.Action.init))
36+
self.viewStore = ViewStore(store, observe: ViewState.init, send: NewGame.Action.init)
3737
super.init(nibName: nil, bundle: nil)
3838
}
3939

0 commit comments

Comments
 (0)