Skip to content

Commit 7337194

Browse files
committed
Merge pull request #19 from RxSwiftCommunity/rxswift-rc
Update to RxSwift 2.0
2 parents 15ea15c + 57ec85e commit 7337194

File tree

9 files changed

+66
-57
lines changed

9 files changed

+66
-57
lines changed

Action.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Pod::Spec.new do |s|
2121
s.source_files = "*.{swift}"
2222

2323
s.frameworks = "Foundation"
24-
s.dependency "RxSwift", '~> 2.0.0-beta'
25-
s.dependency "RxCocoa", '~> 2.0.0-beta'
24+
s.dependency "RxSwift", '~> 2.0.0'
25+
s.dependency "RxCocoa", '~> 2.0.0'
2626

2727
s.watchos.exclude_files = "UIButton+Rx.swift", "UIBarButtonItem+Action.swift", "AlertAction.swift"
2828
s.osx.exclude_files = "UIButton+Rx.swift", "UIBarButtonItem+Action.swift", "AlertAction.swift"

Action.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public final class Action<Input, Element> {
3535
/// Whether or not we're currently executing.
3636
/// Always observed on MainScheduler.
3737
public var executing: Observable<Bool> {
38-
return self._executing.asObservable().observeOn(MainScheduler.sharedInstance)
38+
return self._executing.asObservable().observeOn(MainScheduler.instance)
3939
}
4040
private let _executing = Variable(false)
4141

4242
/// Whether or not we're enabled. Note that this is a *computed* sequence
4343
/// property based on enabledIf initializer and if we're currently executing.
4444
/// Always observed on MainScheduler.
4545
public var enabled: Observable<Bool> {
46-
return _enabled.asObservable().observeOn(MainScheduler.sharedInstance)
46+
return _enabled.asObservable().observeOn(MainScheduler.instance)
4747
}
4848
public private(set) var _enabled = BehaviorSubject(value: true)
4949

@@ -56,7 +56,7 @@ public final class Action<Input, Element> {
5656
}
5757
self.workFactory = workFactory
5858

59-
combineLatest(self._enabledIf, self.executing) { (enabled, executing) -> Bool in
59+
Observable.combineLatest(self._enabledIf, self.executing) { (enabled, executing) -> Bool in
6060
return enabled && !executing
6161
}.bindTo(_enabled).addDisposableTo(disposeBag)
6262
}
@@ -67,7 +67,7 @@ public extension Action {
6767

6868
/// Always enabled.
6969
public convenience init(workFactory: WorkFactory) {
70-
self.init(enabledIf: just(true), workFactory: workFactory)
70+
self.init(enabledIf: .just(true), workFactory: workFactory)
7171
}
7272
}
7373

Demo/Demo/ViewController.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ViewController: UIViewController {
2424
// Demo: add an action to a button in the view
2525
let action = CocoaAction {
2626
print("Button was pressed, showing an alert and keeping the activity indicator spinning while alert is displayed")
27-
return create {
27+
return Observable.create {
2828
[weak self] observer -> Disposable in
2929

3030
// Demo: show an alert and complete the view's button action once the alert's OK button is pressed
@@ -33,7 +33,7 @@ class ViewController: UIViewController {
3333
ok.rx_action = CocoaAction {
3434
print("Alert's OK button was pressed")
3535
observer.onCompleted()
36-
return empty()
36+
return .empty()
3737
}
3838
alertController.addAction(ok)
3939
self!.presentViewController(alertController, animated: true, completion: nil)
@@ -46,12 +46,12 @@ class ViewController: UIViewController {
4646
// Demo: add an action to a UIBarButtonItem in the navigation item
4747
self.navigationItem.rightBarButtonItem!.rx_action = CocoaAction {
4848
print("Bar button item was pressed, simulating a 2 second action")
49-
return empty().delaySubscription(2, MainScheduler.sharedInstance)
49+
return Observable.empty().delaySubscription(2, scheduler: MainScheduler.instance)
5050
}
5151

5252
// Demo: observe the output of both actions, spin an activity indicator
5353
// while performing the work
54-
combineLatest(
54+
Observable.combineLatest(
5555
button.rx_action!.executing,
5656
self.navigationItem.rightBarButtonItem!.rx_action!.executing) {
5757
// we combine two boolean observable and output one boolean

Demo/DemoTests/ActionTests.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class ActionTests: QuickSpec {
121121
var receivedInput: String?
122122
let subject = Action<String, Void>(workFactory: { (input) in
123123
receivedInput = input
124-
return just()
124+
return .just()
125125
})
126126

127127
subject.execute(testInput)
@@ -215,7 +215,7 @@ class ActionTests: QuickSpec {
215215
var invocations = 0
216216
let subject = Action<Void, Void>(workFactory: { _ in
217217
invocations++
218-
return empty()
218+
return .empty()
219219
})
220220

221221
subject.execute()
@@ -234,7 +234,7 @@ class ActionTests: QuickSpec {
234234
it("is externally disabled while executing") {
235235
var observer: AnyObserver<Void>!
236236
let subject = Action<Void, Void>(workFactory: { _ in
237-
return create { (obsv) -> Disposable in
237+
return Observable.create { (obsv) -> Disposable in
238238
observer = obsv
239239
return NopDisposable.instance
240240
}
@@ -254,17 +254,17 @@ class ActionTests: QuickSpec {
254254

255255
describe("disabled") {
256256
it("sends false on enabled observable") {
257-
let subject = Action<Void, Void>(enabledIf: just(false), workFactory: { _ in
258-
return empty()
257+
let subject = Action<Void, Void>(enabledIf: .just(false), workFactory: { _ in
258+
return .empty()
259259
})
260260

261261
let enabled = try! subject.enabled.toBlocking().first()
262262
expect(enabled) == false
263263
}
264264

265265
it("errors observable sends error as next event when execute() is called") {
266-
let subject = Action<Void, Void>(enabledIf: just(false), workFactory: { _ in
267-
return empty()
266+
let subject = Action<Void, Void>(enabledIf: .just(false), workFactory: { _ in
267+
return .empty()
268268
})
269269

270270
var receivedError: ActionError?
@@ -282,8 +282,8 @@ class ActionTests: QuickSpec {
282282
}
283283

284284
it("errors observable sends correct error types when execute() is called") {
285-
let subject = Action<Void, Void>(enabledIf: just(false), workFactory: { _ in
286-
return empty()
285+
let subject = Action<Void, Void>(enabledIf: .just(false), workFactory: { _ in
286+
return .empty()
287287
})
288288

289289
var receivedError: ActionError?
@@ -311,9 +311,9 @@ class ActionTests: QuickSpec {
311311
it("doesn't invoke the work factory") {
312312
var invoked = false
313313

314-
let subject = Action<Void, Void>(enabledIf: just(false), workFactory: { _ in
314+
let subject = Action<Void, Void>(enabledIf: .just(false), workFactory: { _ in
315315
invoked = true
316-
return empty()
316+
return .empty()
317317
})
318318

319319
subject.execute()
@@ -330,7 +330,7 @@ extension String: ErrorType { }
330330
let TestError = "Test Error"
331331

332332
func errorObservable() -> Observable<Void> {
333-
return create({ (observer) -> Disposable in
333+
return .create({ (observer) -> Disposable in
334334
observer.onError(TestError)
335335
return NopDisposable.instance
336336
})
@@ -344,7 +344,7 @@ func errorSubject() -> Action<Void, Void> {
344344

345345
func emptySubject() -> Action<Void, Void> {
346346
return Action(workFactory: { input in
347-
return empty()
347+
return .empty()
348348
})
349349
}
350350

Demo/DemoTests/AlertActionTests.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class AlertActionTests: QuickSpec {
2121
expect(subject.rx_action) === action
2222
}
2323

24-
it("disables the button while executing") {
24+
it("disables the alert action while executing") {
2525
let subject = UIAlertAction.Action("Hi", style: .Default)
2626

2727
var observer: AnyObserver<Void>!
2828
let action = CocoaAction(workFactory: { _ in
29-
return create { (obsv) -> Disposable in
29+
return Observable.create { (obsv) -> Disposable in
3030
observer = obsv
3131
return NopDisposable.instance
3232
}
@@ -41,10 +41,19 @@ class AlertActionTests: QuickSpec {
4141
expect(subject.enabled).toEventually( beTrue() )
4242
}
4343

44-
it("disables the button if the Action is disabled") {
44+
it("disables the alert action if the Action is disabled") {
4545
let subject = UIAlertAction.Action("Hi", style: .Default)
46+
let disposeBag = DisposeBag()
4647

47-
subject.rx_action = emptyAction(just(false))
48+
subject.rx_action = emptyAction(.just(false))
49+
waitUntil { done in
50+
subject.rx_observe(Bool.self, "enabled")
51+
.take(1)
52+
.subscribeNext { _ in
53+
done()
54+
}
55+
.addDisposableTo(disposeBag)
56+
}
4857

4958
expect(subject.enabled) == false
5059
}

Demo/DemoTests/BarButtonTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class BarButtonTests: QuickSpec {
2727

2828
var observer: AnyObserver<Void>!
2929
let action = CocoaAction(workFactory: { _ in
30-
return create { (obsv) -> Disposable in
30+
return Observable.create { (obsv) -> Disposable in
3131
observer = obsv
3232
return NopDisposable.instance
3333
}
@@ -45,7 +45,7 @@ class BarButtonTests: QuickSpec {
4545
it("disables the button if the Action is disabled") {
4646
let subject = UIBarButtonItem(barButtonSystemItem: .Save, target: nil, action: nil)
4747

48-
subject.rx_action = emptyAction(just(false))
48+
subject.rx_action = emptyAction(.just(false))
4949

5050
expect(subject.enabled) == false
5151
}
@@ -54,9 +54,9 @@ class BarButtonTests: QuickSpec {
5454
let subject = UIBarButtonItem(barButtonSystemItem: .Save, target: nil, action: nil)
5555

5656
var executed = false
57-
subject.rx_action = CocoaAction(enabledIf: just(false), workFactory: { _ in
57+
subject.rx_action = CocoaAction(enabledIf: .just(false), workFactory: { _ in
5858
executed = true
59-
return empty()
59+
return .empty()
6060
})
6161

6262
subject.target?.performSelector(subject.action, withObject: subject)
@@ -70,7 +70,7 @@ class BarButtonTests: QuickSpec {
7070
var executed = false
7171
let action = CocoaAction(workFactory: { _ in
7272
executed = true
73-
return empty()
73+
return .empty()
7474
})
7575
subject.rx_action = action
7676

Demo/DemoTests/ButtonTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ButtonTests: QuickSpec {
2727

2828
var observer: AnyObserver<Void>!
2929
let action = CocoaAction(workFactory: { _ in
30-
return create { (obsv) -> Disposable in
30+
return Observable.create { (obsv) -> Disposable in
3131
observer = obsv
3232
return NopDisposable.instance
3333
}
@@ -45,7 +45,7 @@ class ButtonTests: QuickSpec {
4545
it("disables the button if the Action is disabled") {
4646
let subject = UIButton(type: .System)
4747

48-
subject.rx_action = emptyAction(just(false))
48+
subject.rx_action = emptyAction(.just(false))
4949

5050
expect(subject.enabled) == false
5151
}
@@ -54,9 +54,9 @@ class ButtonTests: QuickSpec {
5454
let subject = UIButton(type: .System)
5555

5656
var executed = false
57-
subject.rx_action = CocoaAction(enabledIf: just(false), workFactory: { _ in
57+
subject.rx_action = CocoaAction(enabledIf: .just(false), workFactory: { _ in
5858
executed = true
59-
return empty()
59+
return .empty()
6060
})
6161

6262
subject.sendActionsForControlEvents(.TouchUpInside)
@@ -70,7 +70,7 @@ class ButtonTests: QuickSpec {
7070
var executed = false
7171
let action = CocoaAction(workFactory: { _ in
7272
executed = true
73-
return empty()
73+
return .empty()
7474
})
7575
subject.rx_action = action
7676

@@ -109,8 +109,8 @@ class ButtonTests: QuickSpec {
109109
}
110110
}
111111

112-
func emptyAction(enabledIf: Observable<Bool> = just(true)) -> CocoaAction {
112+
func emptyAction(enabledIf: Observable<Bool> = .just(true)) -> CocoaAction {
113113
return CocoaAction(enabledIf: enabledIf, workFactory: { _ in
114-
return empty()
114+
return .empty()
115115
})
116116
}

Demo/Podfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ end
1717
target 'DemoTests' do
1818

1919
# Dependencies
20-
pod 'RxSwift', '~> 2.0.0-beta'
21-
pod 'RxCocoa', '~> 2.0.0-beta'
22-
pod 'RxBlocking', '~> 2.0.0-beta'
20+
pod 'RxSwift', '~> 2.0.0'
21+
pod 'RxCocoa', '~> 2.0.0'
22+
pod 'RxBlocking', '~> 2.0.0'
2323

2424
# Testing libraries
2525
pod 'Quick'

Demo/Podfile.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
PODS:
2-
- Action (0.3.0):
3-
- RxCocoa (~> 2.0.0-beta)
4-
- RxSwift (~> 2.0.0-beta)
2+
- Action (1.0.0):
3+
- RxCocoa (~> 2.0.0)
4+
- RxSwift (~> 2.0.0)
55
- Nimble (3.0.0)
66
- Quick (0.8.0)
7-
- RxBlocking (2.0.0-beta.4):
8-
- RxSwift (~> 2.0.0-beta)
9-
- RxCocoa (2.0.0-beta.4):
10-
- RxSwift (~> 2.0.0-beta)
11-
- RxSwift (2.0.0-beta.4)
7+
- RxBlocking (2.0.0):
8+
- RxSwift (~> 2.0)
9+
- RxCocoa (2.0.0):
10+
- RxSwift (~> 2.0)
11+
- RxSwift (2.0.0)
1212

1313
DEPENDENCIES:
1414
- Action (from `../`)
1515
- Nimble
1616
- Quick
17-
- RxBlocking (~> 2.0.0-beta)
18-
- RxCocoa (~> 2.0.0-beta)
19-
- RxSwift (~> 2.0.0-beta)
17+
- RxBlocking (~> 2.0.0)
18+
- RxCocoa (~> 2.0.0)
19+
- RxSwift (~> 2.0.0)
2020

2121
EXTERNAL SOURCES:
2222
Action:
2323
:path: "../"
2424

2525
SPEC CHECKSUMS:
26-
Action: da3ac4ae245c10f909fd07db34680a90beb4aa21
26+
Action: 6e9b1bb31f75cf7092b07d4acfaf8e217393b180
2727
Nimble: 4c353d43735b38b545cbb4cb91504588eb5de926
2828
Quick: 563d0f6ec5f72e394645adb377708639b7dd38ab
29-
RxBlocking: 234b0c161315ff3ade25c11e48d74e9ca83158b5
30-
RxCocoa: 4a3e433e6dfe116362ff54423c841cc0f209e009
31-
RxSwift: 191c6b06da783a8671433cf35a54d2ad2fd2d9de
29+
RxBlocking: a95a10ed54eb5d116f6c9a87047ff671e181d07b
30+
RxCocoa: b0ebd70b4f7450bdb3c8987b122f8fd568dc1e2f
31+
RxSwift: d83246efa6f16c50c143bec134649d045498f601
3232

3333
COCOAPODS: 0.39.0

0 commit comments

Comments
 (0)