Skip to content

ViewStore.init(_:observe:) #1448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ Avoid using deprecated APIs in your app. Select a method to see the replacement

## Topics

### Interacting with concurrency
### Creating a view store

- ``ViewStore/init(_:removeDuplicates:)``
- ``ViewStore/init(_:)-1pfeq``

### Interacting with Concurrency

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

### Creating a view store

- ``init(_:removeDuplicates:)``
- ``init(_:)-1pfeq``
- ``init(_:observe:removeDuplicates:)``
- ``init(_:observe:)``
- ``init(_:)-4il0f``
- ``ViewStoreOf``

### Accessing state

- ``state``
- ``state-swift.property``
- ``subscript(dynamicMember:)-kwxk``

### Sending actions
Expand Down
18 changes: 13 additions & 5 deletions Sources/ComposableArchitecture/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import XCTestDynamicOverlay

// MARK: - Deprecated after 0.41.0:

extension ViewStore {
@available(*, deprecated, renamed: "ViewState")
public typealias State = ViewState

@available(*, deprecated, renamed: "ViewAction")
public typealias Action = ViewAction
}

extension ReducerProtocol {
@available(*, deprecated, renamed: "_printChanges")
public func debug() -> _PrintChangesReducer<Self, _CustomDumpPrinter> {
Expand Down Expand Up @@ -541,7 +549,7 @@ extension Effect {
extension ViewStore {
@available(*, deprecated, renamed: "yield(while:)")
@MainActor
public func suspend(while predicate: @escaping (State) -> Bool) async {
public func suspend(while predicate: @escaping (ViewState) -> Bool) async {
await self.yield(while: predicate)
}
}
Expand Down Expand Up @@ -909,7 +917,7 @@ extension Store {
}
}

extension ViewStore where Action: BindableAction, Action.State == State {
extension ViewStore where ViewAction: BindableAction, ViewAction.State == ViewState {
@available(
*, deprecated,
message:
Expand All @@ -922,7 +930,7 @@ extension ViewStore where Action: BindableAction, Action.State == State {
)
@MainActor
public subscript<Value: Equatable>(
dynamicMember keyPath: WritableKeyPath<State, BindableState<Value>>
dynamicMember keyPath: WritableKeyPath<ViewState, BindableState<Value>>
) -> Binding<Value> {
self.binding(
get: { $0[keyPath: keyPath].wrappedValue },
Expand Down Expand Up @@ -1000,8 +1008,8 @@ extension ViewStore {
)
@MainActor
public func binding<Value: Equatable>(
keyPath: WritableKeyPath<State, Value>,
send action: @escaping (BindingAction<State>) -> Action
keyPath: WritableKeyPath<ViewState, Value>,
send action: @escaping (BindingAction<ViewState>) -> ViewAction
) -> Binding<Value> {
self.binding(
get: { $0[keyPath: keyPath] },
Expand Down
10 changes: 5 additions & 5 deletions Sources/ComposableArchitecture/SwiftUI/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,13 @@ extension BindableAction {
}
}

extension ViewStore where Action: BindableAction, Action.State == State {
extension ViewStore where ViewAction: BindableAction, ViewAction.State == ViewState {
/// Returns a binding to the resulting bindable state of a given key path.
///
/// - Parameter keyPath: A key path to a specific bindable state.
/// - Returns: A new binding.
public func binding<Value: Equatable>(
_ keyPath: WritableKeyPath<State, BindableState<Value>>,
_ keyPath: WritableKeyPath<ViewState, BindableState<Value>>,
file: StaticString = #file,
fileID: StaticString = #fileID,
line: UInt = #line
Expand All @@ -137,14 +137,14 @@ extension ViewStore where Action: BindableAction, Action.State == State {
send: { value in
#if DEBUG
let debugger = BindableActionViewStoreDebugger(
value: value, bindableActionType: Action.self, file: file, fileID: fileID, line: line
value: value, bindableActionType: ViewAction.self, file: file, fileID: fileID, line: line
)
let set: (inout State) -> Void = {
let set: (inout ViewState) -> Void = {
$0[keyPath: keyPath].wrappedValue = value
debugger.wasCalled = true
}
#else
let set: (inout State) -> Void = { $0[keyPath: keyPath].wrappedValue = value }
let set: (inout ViewState) -> Void = { $0[keyPath: keyPath].wrappedValue = value }
#endif
return .binding(.init(keyPath: keyPath, set: set, value: value))
}
Expand Down
Loading