Skip to content

Commit

Permalink
Merge pull request #19 from RxSwiftCommunity/rxswift-rc
Browse files Browse the repository at this point in the history
Update to RxSwift 2.0
  • Loading branch information
ashfurrow committed Jan 4, 2016
2 parents 15ea15c + 57ec85e commit 7337194
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Action.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Pod::Spec.new do |s|
s.source_files = "*.{swift}"

s.frameworks = "Foundation"
s.dependency "RxSwift", '~> 2.0.0-beta'
s.dependency "RxCocoa", '~> 2.0.0-beta'
s.dependency "RxSwift", '~> 2.0.0'
s.dependency "RxCocoa", '~> 2.0.0'

s.watchos.exclude_files = "UIButton+Rx.swift", "UIBarButtonItem+Action.swift", "AlertAction.swift"
s.osx.exclude_files = "UIButton+Rx.swift", "UIBarButtonItem+Action.swift", "AlertAction.swift"
Expand Down
8 changes: 4 additions & 4 deletions Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public final class Action<Input, Element> {
/// Whether or not we're currently executing.
/// Always observed on MainScheduler.
public var executing: Observable<Bool> {
return self._executing.asObservable().observeOn(MainScheduler.sharedInstance)
return self._executing.asObservable().observeOn(MainScheduler.instance)
}
private let _executing = Variable(false)

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

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

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

/// Always enabled.
public convenience init(workFactory: WorkFactory) {
self.init(enabledIf: just(true), workFactory: workFactory)
self.init(enabledIf: .just(true), workFactory: workFactory)
}
}

Expand Down
8 changes: 4 additions & 4 deletions Demo/Demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ViewController: UIViewController {
// Demo: add an action to a button in the view
let action = CocoaAction {
print("Button was pressed, showing an alert and keeping the activity indicator spinning while alert is displayed")
return create {
return Observable.create {
[weak self] observer -> Disposable in

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

// Demo: observe the output of both actions, spin an activity indicator
// while performing the work
combineLatest(
Observable.combineLatest(
button.rx_action!.executing,
self.navigationItem.rightBarButtonItem!.rx_action!.executing) {
// we combine two boolean observable and output one boolean
Expand Down
26 changes: 13 additions & 13 deletions Demo/DemoTests/ActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ActionTests: QuickSpec {
var receivedInput: String?
let subject = Action<String, Void>(workFactory: { (input) in
receivedInput = input
return just()
return .just()
})

subject.execute(testInput)
Expand Down Expand Up @@ -215,7 +215,7 @@ class ActionTests: QuickSpec {
var invocations = 0
let subject = Action<Void, Void>(workFactory: { _ in
invocations++
return empty()
return .empty()
})

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

describe("disabled") {
it("sends false on enabled observable") {
let subject = Action<Void, Void>(enabledIf: just(false), workFactory: { _ in
return empty()
let subject = Action<Void, Void>(enabledIf: .just(false), workFactory: { _ in
return .empty()
})

let enabled = try! subject.enabled.toBlocking().first()
expect(enabled) == false
}

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

var receivedError: ActionError?
Expand All @@ -282,8 +282,8 @@ class ActionTests: QuickSpec {
}

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

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

let subject = Action<Void, Void>(enabledIf: just(false), workFactory: { _ in
let subject = Action<Void, Void>(enabledIf: .just(false), workFactory: { _ in
invoked = true
return empty()
return .empty()
})

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

func errorObservable() -> Observable<Void> {
return create({ (observer) -> Disposable in
return .create({ (observer) -> Disposable in
observer.onError(TestError)
return NopDisposable.instance
})
Expand All @@ -344,7 +344,7 @@ func errorSubject() -> Action<Void, Void> {

func emptySubject() -> Action<Void, Void> {
return Action(workFactory: { input in
return empty()
return .empty()
})
}

Expand Down
17 changes: 13 additions & 4 deletions Demo/DemoTests/AlertActionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class AlertActionTests: QuickSpec {
expect(subject.rx_action) === action
}

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

var observer: AnyObserver<Void>!
let action = CocoaAction(workFactory: { _ in
return create { (obsv) -> Disposable in
return Observable.create { (obsv) -> Disposable in
observer = obsv
return NopDisposable.instance
}
Expand All @@ -41,10 +41,19 @@ class AlertActionTests: QuickSpec {
expect(subject.enabled).toEventually( beTrue() )
}

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

subject.rx_action = emptyAction(just(false))
subject.rx_action = emptyAction(.just(false))
waitUntil { done in
subject.rx_observe(Bool.self, "enabled")
.take(1)
.subscribeNext { _ in
done()
}
.addDisposableTo(disposeBag)
}

expect(subject.enabled) == false
}
Expand Down
10 changes: 5 additions & 5 deletions Demo/DemoTests/BarButtonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BarButtonTests: QuickSpec {

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

subject.rx_action = emptyAction(just(false))
subject.rx_action = emptyAction(.just(false))

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

var executed = false
subject.rx_action = CocoaAction(enabledIf: just(false), workFactory: { _ in
subject.rx_action = CocoaAction(enabledIf: .just(false), workFactory: { _ in
executed = true
return empty()
return .empty()
})

subject.target?.performSelector(subject.action, withObject: subject)
Expand All @@ -70,7 +70,7 @@ class BarButtonTests: QuickSpec {
var executed = false
let action = CocoaAction(workFactory: { _ in
executed = true
return empty()
return .empty()
})
subject.rx_action = action

Expand Down
14 changes: 7 additions & 7 deletions Demo/DemoTests/ButtonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ButtonTests: QuickSpec {

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

subject.rx_action = emptyAction(just(false))
subject.rx_action = emptyAction(.just(false))

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

var executed = false
subject.rx_action = CocoaAction(enabledIf: just(false), workFactory: { _ in
subject.rx_action = CocoaAction(enabledIf: .just(false), workFactory: { _ in
executed = true
return empty()
return .empty()
})

subject.sendActionsForControlEvents(.TouchUpInside)
Expand All @@ -70,7 +70,7 @@ class ButtonTests: QuickSpec {
var executed = false
let action = CocoaAction(workFactory: { _ in
executed = true
return empty()
return .empty()
})
subject.rx_action = action

Expand Down Expand Up @@ -109,8 +109,8 @@ class ButtonTests: QuickSpec {
}
}

func emptyAction(enabledIf: Observable<Bool> = just(true)) -> CocoaAction {
func emptyAction(enabledIf: Observable<Bool> = .just(true)) -> CocoaAction {
return CocoaAction(enabledIf: enabledIf, workFactory: { _ in
return empty()
return .empty()
})
}
6 changes: 3 additions & 3 deletions Demo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ end
target 'DemoTests' do

# Dependencies
pod 'RxSwift', '~> 2.0.0-beta'
pod 'RxCocoa', '~> 2.0.0-beta'
pod 'RxBlocking', '~> 2.0.0-beta'
pod 'RxSwift', '~> 2.0.0'
pod 'RxCocoa', '~> 2.0.0'
pod 'RxBlocking', '~> 2.0.0'

# Testing libraries
pod 'Quick'
Expand Down
30 changes: 15 additions & 15 deletions Demo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
PODS:
- Action (0.3.0):
- RxCocoa (~> 2.0.0-beta)
- RxSwift (~> 2.0.0-beta)
- Action (1.0.0):
- RxCocoa (~> 2.0.0)
- RxSwift (~> 2.0.0)
- Nimble (3.0.0)
- Quick (0.8.0)
- RxBlocking (2.0.0-beta.4):
- RxSwift (~> 2.0.0-beta)
- RxCocoa (2.0.0-beta.4):
- RxSwift (~> 2.0.0-beta)
- RxSwift (2.0.0-beta.4)
- RxBlocking (2.0.0):
- RxSwift (~> 2.0)
- RxCocoa (2.0.0):
- RxSwift (~> 2.0)
- RxSwift (2.0.0)

DEPENDENCIES:
- Action (from `../`)
- Nimble
- Quick
- RxBlocking (~> 2.0.0-beta)
- RxCocoa (~> 2.0.0-beta)
- RxSwift (~> 2.0.0-beta)
- RxBlocking (~> 2.0.0)
- RxCocoa (~> 2.0.0)
- RxSwift (~> 2.0.0)

EXTERNAL SOURCES:
Action:
:path: "../"

SPEC CHECKSUMS:
Action: da3ac4ae245c10f909fd07db34680a90beb4aa21
Action: 6e9b1bb31f75cf7092b07d4acfaf8e217393b180
Nimble: 4c353d43735b38b545cbb4cb91504588eb5de926
Quick: 563d0f6ec5f72e394645adb377708639b7dd38ab
RxBlocking: 234b0c161315ff3ade25c11e48d74e9ca83158b5
RxCocoa: 4a3e433e6dfe116362ff54423c841cc0f209e009
RxSwift: 191c6b06da783a8671433cf35a54d2ad2fd2d9de
RxBlocking: a95a10ed54eb5d116f6c9a87047ff671e181d07b
RxCocoa: b0ebd70b4f7450bdb3c8987b122f8fd568dc1e2f
RxSwift: d83246efa6f16c50c143bec134649d045498f601

COCOAPODS: 0.39.0

0 comments on commit 7337194

Please sign in to comment.