diff --git a/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift b/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift index bc6d42e..6def439 100644 --- a/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift +++ b/Sources/ComposableArchitecture/Debugging/ReducerDebugging.swift @@ -109,10 +109,12 @@ extension Reducer { return .concatenate( .fireAndForget { debugEnvironment.queue.async { - let actionOutput = actionFormat == .prettyPrint + let actionOutput = + actionFormat == .prettyPrint ? debugOutput(localAction).indent(by: 2) : debugCaseOutput(localAction).indent(by: 2) - let stateOutput = LocalState.self == Void.self + let stateOutput = + LocalState.self == Void.self ? "" : debugDiff(previousState, nextState).map { "\($0)\n" } ?? " (No state changes)\n" debugEnvironment.printer( diff --git a/Sources/ComposableArchitecture/Debugging/ReducerInstrumentation.swift b/Sources/ComposableArchitecture/Debugging/ReducerInstrumentation.swift index c929b8f..a2d35f5 100644 --- a/Sources/ComposableArchitecture/Debugging/ReducerInstrumentation.swift +++ b/Sources/ComposableArchitecture/Debugging/ReducerInstrumentation.swift @@ -98,7 +98,8 @@ func debugCaseOutput(_ value: Any) -> String { case .tuple: return mirror.children.map { label, value in let childOutput = debugCaseOutputHelp(value) - return "\(label.map { isUnlabeledArgument($0) ? "_:" : "\($0):" } ?? "")\(childOutput.isEmpty ? "" : " \(childOutput)")" + return + "\(label.map { isUnlabeledArgument($0) ? "_:" : "\($0):" } ?? "")\(childOutput.isEmpty ? "" : " \(childOutput)")" } .joined(separator: ", ") default: diff --git a/Sources/ComposableArchitecture/Store.swift b/Sources/ComposableArchitecture/Store.swift index 483b938..8950048 100644 --- a/Sources/ComposableArchitecture/Store.swift +++ b/Sources/ComposableArchitecture/Store.swift @@ -84,7 +84,7 @@ public final class Store { ) localStore.parentDisposable = self.observable .subscribe(onNext: { [weak localStore] newValue in localStore?.state = toLocalState(newValue) - }) + }) return localStore } diff --git a/Tests/ComposableArchitectureTests/ReducerTests.swift b/Tests/ComposableArchitectureTests/ReducerTests.swift index 430ab14..44a9dd7 100644 --- a/Tests/ComposableArchitectureTests/ReducerTests.swift +++ b/Tests/ComposableArchitectureTests/ReducerTests.swift @@ -156,58 +156,58 @@ final class ReducerTests: XCTestCase { ) } - func testDebug_ActionFormat_OnlyLabels() { - enum Action: Equatable { case incr(Bool) } - struct State: Equatable { var count = 0 } - - var logs: [String] = [] - let logsExpectation = self.expectation(description: "logs") - - let reducer = Reducer { state, action, _ in - switch action { - case let .incr(bool): - state.count += bool ? 1 : 0 - return .none - } - } - .debug("[prefix]", actionFormat: .labelsOnly) { _ in - DebugEnvironment( - printer: { - logs.append($0) - logsExpectation.fulfill() - } - ) - } + func testDebug_ActionFormat_OnlyLabels() { + enum Action: Equatable { case incr(Bool) } + struct State: Equatable { var count = 0 } - let viewStore = ViewStore( - Store( - initialState: State(), - reducer: reducer, - environment: () - ) - ) - viewStore.send(.incr(true)) - - self.wait(for: [logsExpectation], timeout: 2) - - XCTAssertEqual( - logs, - [ - #""" - [prefix]: received action: - Action.incr -   State( - − count: 0 - + count: 1 -   ) - - """#, - ] + var logs: [String] = [] + let logsExpectation = self.expectation(description: "logs") + + let reducer = Reducer { state, action, _ in + switch action { + case let .incr(bool): + state.count += bool ? 1 : 0 + return .none + } + } + .debug("[prefix]", actionFormat: .labelsOnly) { _ in + DebugEnvironment( + printer: { + logs.append($0) + logsExpectation.fulfill() + } ) } - func testDefaultSignpost() { - let reducer = Reducer.empty.signpost(log: .default) + let viewStore = ViewStore( + Store( + initialState: State(), + reducer: reducer, + environment: () + ) + ) + viewStore.send(.incr(true)) + + self.wait(for: [logsExpectation], timeout: 2) + + XCTAssertEqual( + logs, + [ + #""" + [prefix]: received action: + Action.incr +   State( + − count: 0 + + count: 1 +   ) + + """# + ] + ) + } + + func testDefaultSignpost() { + let reducer = Reducer.empty.signpost(log: .default) var n = 0 let effect = reducer.run(&n, (), ()) let expectation = self.expectation(description: "effect")