Skip to content

Commit daa381b

Browse files
stephencelismluisbrown
authored andcommitted
Cleanup: Global/Local -> Parent/Child (#1269)
* Make openSettings async. * global/local -> parent/child * error cleanup * Clean up action scoping * cleanup * wip Co-authored-by: Brandon Williams <[email protected]> (cherry picked from commit 799aa18f86cd9df8d7787e0c05c5cd13067c44b9) # Conflicts: # Examples/VoiceMemos/VoiceMemos/VoiceMemosApp.swift # Sources/ComposableArchitecture/Internal/Deprecations.swift # Sources/ComposableArchitecture/Store.swift # Sources/ComposableArchitecture/SwiftUI/SwitchStore.swift # Sources/ComposableArchitecture/TestStore.swift # Sources/ComposableArchitecture/ViewStore.swift
1 parent 7bf7c42 commit daa381b

File tree

12 files changed

+1648
-1641
lines changed

12 files changed

+1648
-1641
lines changed

Examples/VoiceMemos/VoiceMemos/RecordingMemo.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import ComposableArchitecture
22
import ReactiveSwift
33
import SwiftUI
44

5+
struct RecordingMemoFailed: Equatable, Error {}
6+
57
struct RecordingMemoState: Equatable {
68
var date: Date
79
var duration: TimeInterval = 0
@@ -12,8 +14,6 @@ struct RecordingMemoState: Equatable {
1214
case recording
1315
case encoding
1416
}
15-
16-
struct Failed: Equatable, Error {}
1717
}
1818

1919
enum RecordingMemoAction: Equatable {
@@ -44,7 +44,7 @@ let recordingMemoReducer = Reducer<
4444
return .task { [state] in .delegate(.didFinish(.success(state))) }
4545

4646
case .audioRecorderDidFinish(.success(false)):
47-
return .task { .delegate(.didFinish(.failure(RecordingMemoState.Failed()))) }
47+
return .task { .delegate(.didFinish(.failure(RecordingMemoFailed()))) }
4848

4949
case let .audioRecorderDidFinish(.failure(error)):
5050
return .task { .delegate(.didFinish(.failure(error))) }

Examples/VoiceMemos/VoiceMemos/VoiceMemo.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ struct VoiceMemoView: View {
104104
HStack {
105105
TextField(
106106
"Untitled, \(viewStore.date.formatted(date: .numeric, time: .shortened))",
107-
text: viewStore.binding(
108-
get: \.title, send: VoiceMemoAction.titleTextFieldChanged)
107+
text: viewStore.binding(get: \.title, send: { .titleTextFieldChanged($0) })
109108
)
110109

111110
Spacer()

Examples/VoiceMemos/VoiceMemos/VoiceMemos.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct VoiceMemosView: View {
150150
VStack {
151151
List {
152152
ForEachStore(
153-
self.store.scope(state: \.voiceMemos, action: VoiceMemosAction.voiceMemo(id:action:))
153+
self.store.scope(state: \.voiceMemos, action: { .voiceMemo(id: $0, action: $1) })
154154
) {
155155
VoiceMemoView(store: $0)
156156
}
@@ -162,7 +162,7 @@ struct VoiceMemosView: View {
162162
}
163163

164164
IfLetStore(
165-
self.store.scope(state: \.recordingMemo, action: VoiceMemosAction.recordingMemo)
165+
self.store.scope(state: \.recordingMemo, action: { .recordingMemo($0) })
166166
) { store in
167167
RecordingMemoView(store: store)
168168
} else: {

Examples/VoiceMemos/VoiceMemos/VoiceMemosApp.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ struct VoiceMemosApp: App {
1515
audioPlayer: .live,
1616
audioRecorder: .live,
1717
mainRunLoop: QueueScheduler.main,
18-
openSettings: { @MainActor in
18+
openSettings: {
19+
await MainActor.run {
1920
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
21+
}
2022
},
2123
temporaryDirectory: { URL(fileURLWithPath: NSTemporaryDirectory()) },
2224
uuid: { UUID() }

Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,46 +83,46 @@ extension Reducer {
8383
)
8484
}
8585

86-
/// Prints debug messages describing all received local actions and local state mutations.
86+
/// Prints debug messages describing all received actions and state mutations.
8787
///
8888
/// Printing is only done in debug (`#if DEBUG`) builds.
8989
///
9090
/// - Parameters:
9191
/// - prefix: A string with which to prefix all debug messages.
92-
/// - toLocalState: A function that filters state to be printed.
93-
/// - toLocalAction: A case path that filters actions that are printed.
92+
/// - toDebugState: A function that filters state to be printed.
93+
/// - toDebugAction: A case path that filters actions that are printed.
9494
/// - toDebugEnvironment: A function that transforms an environment into a debug environment by
9595
/// describing a print function and a queue to print from. Defaults to a function that ignores
9696
/// the environment and returns a default ``DebugEnvironment`` that uses Swift's `print`
9797
/// function and a background queue.
9898
/// - Returns: A reducer that prints debug messages for all received actions.
99-
public func debug<LocalState, LocalAction>(
99+
public func debug<DebugState, DebugAction>(
100100
_ prefix: String = "",
101-
state toLocalState: @escaping (State) -> LocalState,
102-
action toLocalAction: CasePath<Action, LocalAction>,
101+
state toDebugState: @escaping (State) -> DebugState,
102+
action toDebugAction: CasePath<Action, DebugAction>,
103103
actionFormat: ActionFormat = .prettyPrint,
104104
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
105105
DebugEnvironment()
106106
}
107107
) -> Self {
108108
#if DEBUG
109109
return .init { state, action, environment in
110-
let previousState = toLocalState(state)
110+
let previousState = toDebugState(state)
111111
let effects = self.run(&state, action, environment)
112-
guard let localAction = toLocalAction.extract(from: action) else { return effects }
113-
let nextState = toLocalState(state)
112+
guard let debugAction = toDebugAction.extract(from: action) else { return effects }
113+
let nextState = toDebugState(state)
114114
let debugEnvironment = toDebugEnvironment(environment)
115115
return .concatenate(
116116
.fireAndForget {
117117
debugEnvironment.queue.async {
118118
var actionOutput = ""
119119
if actionFormat == .prettyPrint {
120-
customDump(localAction, to: &actionOutput, indent: 2)
120+
customDump(debugAction, to: &actionOutput, indent: 2)
121121
} else {
122-
actionOutput.write(debugCaseOutput(localAction).indent(by: 2))
122+
actionOutput.write(debugCaseOutput(debugAction).indent(by: 2))
123123
}
124124
let stateOutput =
125-
LocalState.self == Void.self
125+
DebugState.self == Void.self
126126
? ""
127127
: diff(previousState, nextState).map { "\($0)\n" } ?? " (No state changes)\n"
128128
debugEnvironment.printer(

0 commit comments

Comments
 (0)