Skip to content

Commit e8e272a

Browse files
authored
Make Reducer.debug API more like Publisher.print (#111)
* Make Reducer.debug API more like Publisher.print * Deprecations
1 parent 7af4802 commit e8e272a

File tree

4 files changed

+50
-7
lines changed

4 files changed

+50
-7
lines changed

Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ extension Reducer {
1414
/// function and a background queue.
1515
/// - Returns: A reducer that prints debug messages for all received actions.
1616
public func debug(
17-
prefix: String = "",
17+
_ prefix: String = "",
1818
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
1919
DebugEnvironment()
2020
}
2121
) -> Reducer {
22-
self.debug(prefix: prefix, state: { $0 }, action: .self, environment: toDebugEnvironment)
22+
self.debug(prefix, state: { $0 }, action: .self, environment: toDebugEnvironment)
2323
}
2424

2525
/// Prints debug messages describing all received actions.
@@ -34,12 +34,12 @@ extension Reducer {
3434
/// function and a background queue.
3535
/// - Returns: A reducer that prints debug messages for all received actions.
3636
public func debugActions(
37-
prefix: String = "",
37+
_ prefix: String = "",
3838
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
3939
DebugEnvironment()
4040
}
4141
) -> Reducer {
42-
self.debug(prefix: prefix, state: { _ in () }, action: .self, environment: toDebugEnvironment)
42+
self.debug(prefix, state: { _ in () }, action: .self, environment: toDebugEnvironment)
4343
}
4444

4545
/// Prints debug messages describing all received local actions and local state mutations.
@@ -56,7 +56,7 @@ extension Reducer {
5656
/// function and a background queue.
5757
/// - Returns: A reducer that prints debug messages for all received actions.
5858
public func debug<LocalState, LocalAction>(
59-
prefix: String = "",
59+
_ prefix: String = "",
6060
state toLocalState: @escaping (State) -> LocalState,
6161
action toLocalAction: CasePath<Action, LocalAction>,
6262
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in

Sources/ComposableArchitecture/Internal/Deprecations.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
import Combine
22

3+
// NB: Deprecated after 0.1.4:
4+
5+
extension Reducer {
6+
@available(*, deprecated, renamed: "debug(_:environment:)")
7+
public func debug(
8+
prefix: String,
9+
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
10+
DebugEnvironment()
11+
}
12+
) -> Reducer {
13+
self.debug(prefix, state: { $0 }, action: .self, environment: toDebugEnvironment)
14+
}
15+
16+
@available(*, deprecated, renamed: "debugActions(_:environment:)")
17+
public func debugActions(
18+
prefix: String,
19+
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
20+
DebugEnvironment()
21+
}
22+
) -> Reducer {
23+
self.debug(prefix, state: { _ in () }, action: .self, environment: toDebugEnvironment)
24+
}
25+
26+
@available(*, deprecated, renamed: "debug(_:state:action:environment:)")
27+
public func debug<LocalState, LocalAction>(
28+
prefix: String,
29+
state toLocalState: @escaping (State) -> LocalState,
30+
action toLocalAction: CasePath<Action, LocalAction>,
31+
environment toDebugEnvironment: @escaping (Environment) -> DebugEnvironment = { _ in
32+
DebugEnvironment()
33+
}
34+
) -> Reducer {
35+
self.debug(prefix, state: toLocalState, action: toLocalAction, environment: toDebugEnvironment)
36+
}
37+
}
38+
39+
extension WithViewStore {
40+
@available(*, deprecated, renamed: "debug(_:)")
41+
public func debug(prefix: String) -> Self {
42+
self.debug(prefix)
43+
}
44+
}
45+
346
// NB: Deprecated after 0.1.3:
447

548
extension Effect {

Sources/ComposableArchitecture/SwiftUI/WithViewStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public struct WithViewStore<State, Action, Content>: View where Content: View {
5656
///
5757
/// - Parameter prefix: A string with which to prefix all debug messages.
5858
/// - Returns: A structure that prints debug messages for all computations.
59-
public func debug(prefix: String = "") -> Self {
59+
public func debug(_ prefix: String = "") -> Self {
6060
var view = self
6161
view.prefix = prefix
6262
return view

Tests/ComposableArchitectureTests/ReducerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ final class ReducerTests: XCTestCase {
107107
state.count += 1
108108
return .none
109109
}
110-
.debug(prefix: "[prefix]") { _ in
110+
.debug("[prefix]") { _ in
111111
DebugEnvironment(
112112
printer: {
113113
logs.append($0)

0 commit comments

Comments
 (0)