Skip to content
Permalink
Browse files

Use RxSwift 5 and RxExpect 2

  • Loading branch information...
devxoul committed Jun 14, 2019
1 parent 92bc1b2 commit d7cd75d275cef4f1cb17a935b4a884f6e40bab94
@@ -6,17 +6,17 @@
"repositoryURL": "https://github.com/devxoul/RxExpect.git",
"state": {
"branch": null,
"revision": "d27d2f730a41728e0f4ed7d8326e14296d3a2766",
"version": "1.1.0"
"revision": "c3a3bb3d46ee831582c6619ecc48cda1cdbff890",
"version": "2.0.0"
}
},
{
"package": "RxSwift",
"repositoryURL": "https://github.com/ReactiveX/RxSwift.git",
"state": {
"branch": null,
"revision": "0df62b4d562f8620d4b795b18e4adf0b631527a1",
"version": "4.3.1"
"revision": "b3e888b4972d9bc76495dd74d30a8c7fad4b9395",
"version": "5.0.1"
}
}
]
@@ -11,8 +11,8 @@ let package = Package(
.library(name: "ReactorKit", targets: ["ReactorKit"]),
],
dependencies: [
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "4.0.0")),
.package(url: "https://github.com/devxoul/RxExpect.git", .upToNextMajor(from: "1.0.0"))
.package(url: "https://github.com/ReactiveX/RxSwift.git", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/devxoul/RxExpect.git", .upToNextMajor(from: "2.0.0"))
],
targets: [
.target(name: "ReactorKit", dependencies: ["ReactorKitRuntime", "RxSwift"]),
@@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.source_files = "Sources/**/*.{swift,h,m}"
s.frameworks = "Foundation"
s.swift_version = "5.0"
s.dependency "RxSwift", ">= 4.0.0"
s.dependency "RxSwift", "~> 5.0"

s.ios.deployment_target = "8.0"
s.osx.deployment_target = "10.11"
@@ -12,7 +12,6 @@ import RxSwift

/// A special subject for Reactor's Action. It only emits `.next` event.
public final class ActionSubject<Element>: ObservableType, ObserverType, SubjectType {
public typealias E = Element
typealias Key = UInt

var lock = NSRecursiveLock()
@@ -32,7 +31,7 @@ public final class ActionSubject<Element>: ObservableType, ObserverType, Subject
}
#endif

public func subscribe<O: ObserverType>(_ observer: O) -> Disposable where O.E == Element {
public func subscribe<O: ObserverType>(_ observer: O) -> Disposable where O.Element == Element {
self.lock.lock()
let key = self.nextKey
self.nextKey += 1
@@ -11,8 +11,6 @@ import RxSwift
///
/// Unlike `BehaviorSubject` it can't terminate with error or completed.
public final class StateRelay<Element>: ObservableType {
public typealias E = Element

private let _subject: BehaviorSubject<Element>

/// Accepts `event` and emits it to subscribers
@@ -41,7 +39,7 @@ public final class StateRelay<Element>: ObservableType {
}

/// Subscribes observer
public func subscribe<O: ObserverType>(_ observer: O) -> Disposable where O.E == E {
public func subscribe<O: ObserverType>(_ observer: O) -> Disposable where O.Element == Element {
return _subject.subscribe(observer)
}

@@ -21,15 +21,15 @@ final class ActionSubjectTests: XCTestCase {
let test = RxExpect()
let subject = ActionSubject<Int>()
test.input(subject, [
next(100, 1),
next(200, 2),
next(300, 3),
.next(100, 1),
.next(200, 2),
.next(300, 3),
])
test.assert(subject) { events in
XCTAssertEqual(events, [
next(100, 1),
next(200, 2),
next(300, 3),
.next(100, 1),
.next(200, 2),
.next(300, 3),
])
}
}
@@ -38,14 +38,14 @@ final class ActionSubjectTests: XCTestCase {
let test = RxExpect()
let subject = ActionSubject<Int>()
test.input(subject, [
next(100, 1),
error(200, TestError()),
next(300, 3),
.next(100, 1),
.error(200, TestError()),
.next(300, 3),
])
test.assert(subject) { events in
XCTAssertEqual(events, [
next(100, 1),
next(300, 3),
.next(100, 1),
.next(300, 3),
])
}
}
@@ -54,14 +54,14 @@ final class ActionSubjectTests: XCTestCase {
let test = RxExpect()
let subject = ActionSubject<Int>()
test.input(subject, [
next(100, 1),
completed(200),
next(300, 3),
.next(100, 1),
.completed(200),
.next(300, 3),
])
test.assert(subject) { events in
XCTAssertEqual(events, [
next(100, 1),
next(300, 3),
.next(100, 1),
.next(300, 3),
])
}
}
@@ -9,7 +9,7 @@ final class ReactorTests: XCTestCase {
let test = RxExpect()
let reactor = test.retain(TestReactor())
test.input(reactor.action, [
next(100, ["action"]),
.next(100, ["action"]),
])
test.assert(reactor.state) { events in
XCTAssertEqual(events.elements.count, 2)
@@ -47,26 +47,26 @@ final class ReactorTests: XCTestCase {
let test = RxExpect()
let reactor = test.retain(CounterReactor())
let action1 = test.scheduler.createHotObservable([
next(100, Void()),
next(200, Void()),
error(300, TestError()),
next(400, Void()),
.next(100, Void()),
.next(200, Void()),
.error(300, TestError()),
.next(400, Void()),
])
let action2 = test.scheduler.createHotObservable([
error(300, TestError()),
next(500, Void()),
next(600, Void()),
.error(300, TestError()),
.next(500, Void()),
.next(600, Void()),
])
action1.subscribe(reactor.action).disposed(by: test.disposeBag)
action2.subscribe(reactor.action).disposed(by: test.disposeBag)
test.assert(reactor.state) { events in
XCTAssertEqual(events, [
next(0, 0),
next(100, 1),
next(200, 2),
next(400, 3),
next(500, 4),
next(600, 5),
.next(0, 0),
.next(100, 1),
.next(200, 2),
.next(400, 3),
.next(500, 4),
.next(600, 5),
])
}
}
@@ -76,11 +76,11 @@ final class ReactorTests: XCTestCase {
let reactor = test.retain(CounterReactor())
reactor.stateForTriggerError = 2
test.input(reactor.action, [
next(100, Void()),
next(200, Void()),
next(300, Void()), // error will be emit on this mutate
next(400, Void()),
next(500, Void()),
.next(100, Void()),
.next(200, Void()),
.next(300, Void()), // error will be emit on this mutate
.next(400, Void()),
.next(500, Void()),
])
test.assert(reactor.state) { events in
XCTAssertEqual(events.elements, [0, 1, 2, 3, 4, 5])
@@ -91,26 +91,26 @@ final class ReactorTests: XCTestCase {
let test = RxExpect()
let reactor = test.retain(CounterReactor())
let action1 = test.scheduler.createHotObservable([
next(100, Void()),
next(200, Void()),
completed(300),
next(400, Void()),
.next(100, Void()),
.next(200, Void()),
.completed(300),
.next(400, Void()),
])
let action2 = test.scheduler.createHotObservable([
completed(300),
next(500, Void()),
next(600, Void()),
.completed(300),
.next(500, Void()),
.next(600, Void()),
])
action1.subscribe(reactor.action).disposed(by: test.disposeBag)
action2.subscribe(reactor.action).disposed(by: test.disposeBag)
test.assert(reactor.state) { events in
XCTAssertEqual(events, [
next(0, 0),
next(100, 1),
next(200, 2),
next(400, 3),
next(500, 4),
next(600, 5),
.next(0, 0),
.next(100, 1),
.next(200, 2),
.next(400, 3),
.next(500, 4),
.next(600, 5),
])
}
}
@@ -120,11 +120,11 @@ final class ReactorTests: XCTestCase {
let reactor = test.retain(CounterReactor())
reactor.stateForTriggerCompleted = 2
test.input(reactor.action, [
next(100, Void()),
next(200, Void()),
next(300, Void()), // completed will be emit on this mutate
next(400, Void()),
next(500, Void()),
.next(100, Void()),
.next(200, Void()),
.next(300, Void()), // completed will be emit on this mutate
.next(400, Void()),
.next(500, Void()),
])
test.assert(reactor.state) { events in
XCTAssertEqual(events.elements, [0, 1, 2, 3, 4, 5])
@@ -135,10 +135,10 @@ final class ReactorTests: XCTestCase {
let test = RxExpect()
let reactor = test.retain(StopwatchReactor(scheduler: test.scheduler))
test.input(reactor.action, [
next(1, .start),
next(5, .stop),
next(6, .start),
next(9, .stop),
.next(1, .start),
.next(5, .stop),
.next(6, .start),
.next(9, .stop),
])
test.assert(reactor.state) { events in
XCTAssertEqual(events.elements, [
@@ -295,7 +295,7 @@ private final class StopwatchReactor: Reactor {
switch action {
case .start:
let stopAction = self.action.filter { $0 == .stop }
return Observable<Int>.interval(1, scheduler: self.scheduler)
return Observable<Int>.interval(.seconds(1), scheduler: self.scheduler)
.map { _ in 1 }
.takeUntil(stopAction)

0 comments on commit d7cd75d

Please sign in to comment.
You can’t perform that action at this time.