Skip to content

Commit 57ec85e

Browse files
committed
Shorten Observable static functions where possible
1 parent b4072dd commit 57ec85e

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

Action.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public extension Action {
6767

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

Demo/Demo/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 Observable.empty()
36+
return .empty()
3737
}
3838
alertController.addAction(ok)
3939
self!.presentViewController(alertController, animated: true, completion: nil)

Demo/DemoTests/ActionTests.swift

Lines changed: 12 additions & 12 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 Observable.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 Observable.empty()
218+
return .empty()
219219
})
220220

221221
subject.execute()
@@ -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: Observable.just(false), workFactory: { _ in
258-
return Observable.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: Observable.just(false), workFactory: { _ in
267-
return Observable.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: Observable.just(false), workFactory: { _ in
286-
return Observable.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: Observable.just(false), workFactory: { _ in
314+
let subject = Action<Void, Void>(enabledIf: .just(false), workFactory: { _ in
315315
invoked = true
316-
return Observable.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 Observable.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 Observable.empty()
347+
return .empty()
348348
})
349349
}
350350

Demo/DemoTests/BarButtonTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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(Observable.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: Observable.just(false), workFactory: { _ in
57+
subject.rx_action = CocoaAction(enabledIf: .just(false), workFactory: { _ in
5858
executed = true
59-
return Observable.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 Observable.empty()
73+
return .empty()
7474
})
7575
subject.rx_action = action
7676

Demo/DemoTests/ButtonTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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(Observable.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: Observable.just(false), workFactory: { _ in
57+
subject.rx_action = CocoaAction(enabledIf: .just(false), workFactory: { _ in
5858
executed = true
59-
return Observable.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 Observable.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> = Observable.just(true)) -> CocoaAction {
112+
func emptyAction(enabledIf: Observable<Bool> = .just(true)) -> CocoaAction {
113113
return CocoaAction(enabledIf: enabledIf, workFactory: { _ in
114-
return Observable.empty()
114+
return .empty()
115115
})
116116
}

0 commit comments

Comments
 (0)