Skip to content

Commit

Permalink
Merge branch 'master' of github.com:dannyhertz/rx-swift-composable-ar…
Browse files Browse the repository at this point in the history
…chitecture
  • Loading branch information
dannyhertz committed Jul 1, 2020
2 parents 1385a6d + dea92d2 commit dbbac59
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Sources/ComposableArchitecture/Store.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public final class Store<State, Action> {
)
localStore.parentDisposable = self.observable
.subscribe(onNext: { [weak localStore] newValue in localStore?.state = toLocalState(newValue)
})
})
return localStore
}

Expand Down
96 changes: 48 additions & 48 deletions Tests/ComposableArchitectureTests/ReducerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, Void> { 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, Void> { 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<Int, Void, Void>.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<Int, Void, Void>.empty.signpost(log: .default)
var n = 0
let effect = reducer.run(&n, (), ())
let expectation = self.expectation(description: "effect")
Expand Down

0 comments on commit dbbac59

Please sign in to comment.