Skip to content

Commit

Permalink
Run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyhertz authored and actions-user committed Aug 4, 2020
1 parent d8524e9 commit 6372faa
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 95 deletions.
6 changes: 4 additions & 2 deletions Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ extension Store {
else: @escaping () -> Void
) -> Disposable where State == Wrapped? {

let elseDisposable = self
let elseDisposable =
self
.scope(
state: { state in
state.distinctUntilChanged({ ($0 != nil) == ($1 != nil) })
Expand All @@ -54,7 +55,8 @@ extension Store {
if store.state == nil { `else`() }
})

let unwrapDisposable = self
let unwrapDisposable =
self
.scope(
state: { state in
state.distinctUntilChanged({ ($0 != nil) == ($1 != nil) })
Expand Down
187 changes: 94 additions & 93 deletions Tests/ComposableArchitectureTests/StoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,119 +235,120 @@ final class StoreTests: XCTestCase {
XCTAssertEqual(ViewStore(store).state, 100_000)
}

func testPublisherScope() {
let appReducer = Reducer<Int, Bool, Void> { state, action, _ in
state += action ? 1 : 0
return .none
}
func testPublisherScope() {
let appReducer = Reducer<Int, Bool, Void> { state, action, _ in
state += action ? 1 : 0
return .none
}

let parentStore = Store(initialState: 0, reducer: appReducer, environment: ())
let parentStore = Store(initialState: 0, reducer: appReducer, environment: ())

var outputs: [Int] = []
var outputs: [Int] = []

parentStore
.scope { $0.distinctUntilChanged() }
.subscribe(onNext: {
outputs.append($0.state)
})
.disposed(by: disposeBag)
parentStore
.scope { $0.distinctUntilChanged() }
.subscribe(onNext: {
outputs.append($0.state)
})
.disposed(by: disposeBag)

XCTAssertEqual(outputs, [0])
XCTAssertEqual(outputs, [0])

parentStore.send(true)
XCTAssertEqual(outputs, [0, 1])
parentStore.send(true)
XCTAssertEqual(outputs, [0, 1])

parentStore.send(false)
XCTAssertEqual(outputs, [0, 1])
parentStore.send(false)
XCTAssertEqual(outputs, [0, 1])
parentStore.send(false)
XCTAssertEqual(outputs, [0, 1])
parentStore.send(false)
XCTAssertEqual(outputs, [0, 1])
}
parentStore.send(false)
XCTAssertEqual(outputs, [0, 1])
parentStore.send(false)
XCTAssertEqual(outputs, [0, 1])
parentStore.send(false)
XCTAssertEqual(outputs, [0, 1])
parentStore.send(false)
XCTAssertEqual(outputs, [0, 1])
}

func testIfLetAfterScope() {
struct AppState {
var count: Int?
}
func testIfLetAfterScope() {
struct AppState {
var count: Int?
}

let appReducer = Reducer<AppState, Int?, Void> { state, action, _ in
state.count = action
return .none
}
let appReducer = Reducer<AppState, Int?, Void> { state, action, _ in
state.count = action
return .none
}

let parentStore = Store(initialState: AppState(), reducer: appReducer, environment: ())
let parentStore = Store(initialState: AppState(), reducer: appReducer, environment: ())

// NB: This test needs to hold a strong reference to the emitted stores
var outputs: [Int?] = []
var stores: [Any] = []
// NB: This test needs to hold a strong reference to the emitted stores
var outputs: [Int?] = []
var stores: [Any] = []

parentStore
.scope(state: \.count)
.ifLet(
then: { store in
stores.append(store)
outputs.append(store.state)
parentStore
.scope(state: \.count)
.ifLet(
then: { store in
stores.append(store)
outputs.append(store.state)
},
else: {
outputs.append(nil)
})
.disposed(by: disposeBag)

XCTAssertEqual(outputs, [nil])

parentStore.send(1)
XCTAssertEqual(outputs, [nil, 1])

parentStore.send(nil)
XCTAssertEqual(outputs, [nil, 1, nil])
outputs.append(nil)
}
)
.disposed(by: disposeBag)

parentStore.send(1)
XCTAssertEqual(outputs, [nil, 1, nil, 1])
XCTAssertEqual(outputs, [nil])

parentStore.send(nil)
XCTAssertEqual(outputs, [nil, 1, nil, 1, nil])
parentStore.send(1)
XCTAssertEqual(outputs, [nil, 1])

parentStore.send(1)
XCTAssertEqual(outputs, [nil, 1, nil, 1, nil, 1])
parentStore.send(nil)
XCTAssertEqual(outputs, [nil, 1, nil])

parentStore.send(nil)
XCTAssertEqual(outputs, [nil, 1, nil, 1, nil, 1, nil])
}
parentStore.send(1)
XCTAssertEqual(outputs, [nil, 1, nil, 1])

func testIfLetTwo() {
let parentStore = Store(
initialState: 0,
reducer: Reducer<Int?, Bool, Void> { state, action, _ in
if action {
state? += 1
return .none
} else {
return Effect(value: true)
.observeOn(MainScheduler.instance)
.eraseToEffect()
}
},
environment: ()
)
parentStore.send(nil)
XCTAssertEqual(outputs, [nil, 1, nil, 1, nil])

parentStore.ifLet { childStore in
let vs = ViewStore(childStore)
parentStore.send(1)
XCTAssertEqual(outputs, [nil, 1, nil, 1, nil, 1])

vs
.publisher
.subscribe(onNext: { _ in })
.disposed(by: self.disposeBag)
parentStore.send(nil)
XCTAssertEqual(outputs, [nil, 1, nil, 1, nil, 1, nil])
}

vs.send(false)
_ = XCTWaiter.wait(for: [.init()], timeout: 0.1)
vs.send(false)
_ = XCTWaiter.wait(for: [.init()], timeout: 0.1)
vs.send(false)
_ = XCTWaiter.wait(for: [.init()], timeout: 0.1)
XCTAssertEqual(vs.state, 3)
}
.disposed(by: disposeBag)
func testIfLetTwo() {
let parentStore = Store(
initialState: 0,
reducer: Reducer<Int?, Bool, Void> { state, action, _ in
if action {
state? += 1
return .none
} else {
return Effect(value: true)
.observeOn(MainScheduler.instance)
.eraseToEffect()
}
},
environment: ()
)

parentStore.ifLet { childStore in
let vs = ViewStore(childStore)

vs
.publisher
.subscribe(onNext: { _ in })
.disposed(by: self.disposeBag)

vs.send(false)
_ = XCTWaiter.wait(for: [.init()], timeout: 0.1)
vs.send(false)
_ = XCTWaiter.wait(for: [.init()], timeout: 0.1)
vs.send(false)
_ = XCTWaiter.wait(for: [.init()], timeout: 0.1)
XCTAssertEqual(vs.state, 3)
}
.disposed(by: disposeBag)
}
}

0 comments on commit 6372faa

Please sign in to comment.