Skip to content

Commit 55755c3

Browse files
authored
ViewStore.init(_:observe:) (#1448)
* ViewStore.init(_:observe:) * clean up
1 parent bcae29f commit 55755c3

File tree

5 files changed

+246
-46
lines changed

5 files changed

+246
-46
lines changed

Sources/ComposableArchitecture/Documentation.docc/Extensions/Deprecations/ViewStoreDeprecations.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ Avoid using deprecated APIs in your app. Select a method to see the replacement
88

99
## Topics
1010

11-
### Interacting with concurrency
11+
### Creating a view store
12+
13+
- ``ViewStore/init(_:removeDuplicates:)``
14+
- ``ViewStore/init(_:)-1pfeq``
15+
16+
### Interacting with Concurrency
1217

1318
- ``ViewStore/suspend(while:)``
1419

Sources/ComposableArchitecture/Documentation.docc/Extensions/ViewStore.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
### Creating a view store
66

7-
- ``init(_:removeDuplicates:)``
8-
- ``init(_:)-1pfeq``
7+
- ``init(_:observe:removeDuplicates:)``
8+
- ``init(_:observe:)``
99
- ``init(_:)-4il0f``
1010
- ``ViewStoreOf``
1111

1212
### Accessing state
1313

14-
- ``state``
14+
- ``state-swift.property``
1515
- ``subscript(dynamicMember:)-kwxk``
1616

1717
### Sending actions

Sources/ComposableArchitecture/Internal/Deprecations.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ import XCTestDynamicOverlay
55

66
// MARK: - Deprecated after 0.41.0:
77

8+
extension ViewStore {
9+
@available(*, deprecated, renamed: "ViewState")
10+
public typealias State = ViewState
11+
12+
@available(*, deprecated, renamed: "ViewAction")
13+
public typealias Action = ViewAction
14+
}
15+
816
extension ReducerProtocol {
917
@available(*, deprecated, renamed: "_printChanges")
1018
public func debug() -> _PrintChangesReducer<Self, _CustomDumpPrinter> {
@@ -541,7 +549,7 @@ extension Effect {
541549
extension ViewStore {
542550
@available(*, deprecated, renamed: "yield(while:)")
543551
@MainActor
544-
public func suspend(while predicate: @escaping (State) -> Bool) async {
552+
public func suspend(while predicate: @escaping (ViewState) -> Bool) async {
545553
await self.yield(while: predicate)
546554
}
547555
}
@@ -909,7 +917,7 @@ extension Store {
909917
}
910918
}
911919

912-
extension ViewStore where Action: BindableAction, Action.State == State {
920+
extension ViewStore where ViewAction: BindableAction, ViewAction.State == ViewState {
913921
@available(
914922
*, deprecated,
915923
message:
@@ -922,7 +930,7 @@ extension ViewStore where Action: BindableAction, Action.State == State {
922930
)
923931
@MainActor
924932
public subscript<Value: Equatable>(
925-
dynamicMember keyPath: WritableKeyPath<State, BindableState<Value>>
933+
dynamicMember keyPath: WritableKeyPath<ViewState, BindableState<Value>>
926934
) -> Binding<Value> {
927935
self.binding(
928936
get: { $0[keyPath: keyPath].wrappedValue },
@@ -1000,8 +1008,8 @@ extension ViewStore {
10001008
)
10011009
@MainActor
10021010
public func binding<Value: Equatable>(
1003-
keyPath: WritableKeyPath<State, Value>,
1004-
send action: @escaping (BindingAction<State>) -> Action
1011+
keyPath: WritableKeyPath<ViewState, Value>,
1012+
send action: @escaping (BindingAction<ViewState>) -> ViewAction
10051013
) -> Binding<Value> {
10061014
self.binding(
10071015
get: { $0[keyPath: keyPath] },

Sources/ComposableArchitecture/SwiftUI/Binding.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ extension BindableAction {
121121
}
122122
}
123123

124-
extension ViewStore where Action: BindableAction, Action.State == State {
124+
extension ViewStore where ViewAction: BindableAction, ViewAction.State == ViewState {
125125
/// Returns a binding to the resulting bindable state of a given key path.
126126
///
127127
/// - Parameter keyPath: A key path to a specific bindable state.
128128
/// - Returns: A new binding.
129129
public func binding<Value: Equatable>(
130-
_ keyPath: WritableKeyPath<State, BindableState<Value>>,
130+
_ keyPath: WritableKeyPath<ViewState, BindableState<Value>>,
131131
file: StaticString = #file,
132132
fileID: StaticString = #fileID,
133133
line: UInt = #line
@@ -137,14 +137,14 @@ extension ViewStore where Action: BindableAction, Action.State == State {
137137
send: { value in
138138
#if DEBUG
139139
let debugger = BindableActionViewStoreDebugger(
140-
value: value, bindableActionType: Action.self, file: file, fileID: fileID, line: line
140+
value: value, bindableActionType: ViewAction.self, file: file, fileID: fileID, line: line
141141
)
142-
let set: (inout State) -> Void = {
142+
let set: (inout ViewState) -> Void = {
143143
$0[keyPath: keyPath].wrappedValue = value
144144
debugger.wasCalled = true
145145
}
146146
#else
147-
let set: (inout State) -> Void = { $0[keyPath: keyPath].wrappedValue = value }
147+
let set: (inout ViewState) -> Void = { $0[keyPath: keyPath].wrappedValue = value }
148148
#endif
149149
return .binding(.init(keyPath: keyPath, set: set, value: value))
150150
}

0 commit comments

Comments
 (0)