Skip to content

Commit f639ff4

Browse files
committed
Adds asSignal to ControlEvent.
1 parent 586f695 commit f639ff4

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed

.jazzy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ custom_categories:
5353
- SharedSequence
5454
- name: RxCocoa/Traits/Signal
5555
children:
56+
- ControlEvent+Signal
5657
- ObservableConvertibleType+Signal
5758
- PublishRelay+Signal
5859
- Signal+Subscription

Rx.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@
136136
C8091C531FAA3588001DB32A /* ObservableConvertibleType+SharedSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8091C521FAA3588001DB32A /* ObservableConvertibleType+SharedSequence.swift */; };
137137
C8091C541FAA3588001DB32A /* ObservableConvertibleType+SharedSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8091C521FAA3588001DB32A /* ObservableConvertibleType+SharedSequence.swift */; };
138138
C8091C551FAA3588001DB32A /* ObservableConvertibleType+SharedSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8091C521FAA3588001DB32A /* ObservableConvertibleType+SharedSequence.swift */; };
139+
C8091C571FAA39C1001DB32A /* ControlEvent+Signal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8091C561FAA39C1001DB32A /* ControlEvent+Signal.swift */; };
140+
C8091C581FAA39C1001DB32A /* ControlEvent+Signal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8091C561FAA39C1001DB32A /* ControlEvent+Signal.swift */; };
141+
C8091C591FAA39C1001DB32A /* ControlEvent+Signal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8091C561FAA39C1001DB32A /* ControlEvent+Signal.swift */; };
142+
C8091C5A1FAA39C1001DB32A /* ControlEvent+Signal.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8091C561FAA39C1001DB32A /* ControlEvent+Signal.swift */; };
139143
C8093CC51B8A72BE0088E94D /* Cancelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093C491B8A72BE0088E94D /* Cancelable.swift */; };
140144
C8093CC61B8A72BE0088E94D /* Cancelable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093C491B8A72BE0088E94D /* Cancelable.swift */; };
141145
C8093CC71B8A72BE0088E94D /* AsyncLock.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093C4B1B8A72BE0088E94D /* AsyncLock.swift */; };
@@ -1776,6 +1780,7 @@
17761780
C801DE491F6EBB84008DB060 /* Observable+PrimitiveSequenceTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Observable+PrimitiveSequenceTest.swift"; sourceTree = "<group>"; };
17771781
C8091C4D1FAA345C001DB32A /* ObservableConvertibleType+SharedSequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ObservableConvertibleType+SharedSequence.swift"; sourceTree = "<group>"; };
17781782
C8091C521FAA3588001DB32A /* ObservableConvertibleType+SharedSequence.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ObservableConvertibleType+SharedSequence.swift"; sourceTree = "<group>"; };
1783+
C8091C561FAA39C1001DB32A /* ControlEvent+Signal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ControlEvent+Signal.swift"; sourceTree = "<group>"; };
17791784
C809396D1B8A71760088E94D /* RxCocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxCocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; };
17801785
C80939E71B8A71840088E94D /* RxCocoa.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxCocoa.framework; sourceTree = BUILT_PRODUCTS_DIR; };
17811786
C8093BC71B8A71F00088E94D /* RxBlocking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxBlocking.framework; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -2924,6 +2929,7 @@
29242929
children = (
29252930
C85E6FBB1F52FF4F00C5681E /* Signal.swift */,
29262931
C8B0F7141F530F5900548EBE /* PublishRelay+Signal.swift */,
2932+
C8091C561FAA39C1001DB32A /* ControlEvent+Signal.swift */,
29272933
C8B0F7211F53135100548EBE /* ObservableConvertibleType+Signal.swift */,
29282934
C8D970CD1F5324D90058F2FE /* Signal+Subscription.swift */,
29292935
);
@@ -4105,6 +4111,7 @@
41054111
F31F35B01BB4FED800961002 /* UIStepper+Rx.swift in Sources */,
41064112
C8B0F7221F53135100548EBE /* ObservableConvertibleType+Signal.swift in Sources */,
41074113
C89AB1C61DAAC3350065FBE6 /* ControlEvent.swift in Sources */,
4114+
C8091C571FAA39C1001DB32A /* ControlEvent+Signal.swift in Sources */,
41084115
C882542D1B8A752B00B02D69 /* UIImageView+Rx.swift in Sources */,
41094116
A520FFFC1F0D291500573734 /* RxPickerViewDataSourceProxy.swift in Sources */,
41104117
C882542A1B8A752B00B02D69 /* UIControl+Rx.swift in Sources */,
@@ -4207,6 +4214,7 @@
42074214
C8A81CA11E05E82C0008DEF4 /* DispatchQueue+Extensions.swift in Sources */,
42084215
C88F76821CE5341700D5A014 /* TextInput.swift in Sources */,
42094216
C8C8BCD01F8944B800501D4D /* BehaviorRelay.swift in Sources */,
4217+
C8091C581FAA39C1001DB32A /* ControlEvent+Signal.swift in Sources */,
42104218
C89AB1DF1DAAC3350065FBE6 /* ObservableConvertibleType+Driver.swift in Sources */,
42114219
C89AB1D71DAAC3350065FBE6 /* Driver+Subscription.swift in Sources */,
42124220
C89AB2511DAAC3A60065FBE6 /* _RXObjCRuntime.m in Sources */,
@@ -5355,6 +5363,7 @@
53555363
C89AB22A1DAAC33F0065FBE6 /* RxCocoa.swift in Sources */,
53565364
54D213931CE08DDB0028D5B4 /* UINavigationItem+Rx.swift in Sources */,
53575365
C8F0C01A1BBBFBB9001B112F /* RxCollectionViewDelegateProxy.swift in Sources */,
5366+
C8091C5A1FAA39C1001DB32A /* ControlEvent+Signal.swift in Sources */,
53585367
C817729B1E7F408100EA679B /* Deprecated.swift in Sources */,
53595368
C89AB1E11DAAC3350065FBE6 /* ObservableConvertibleType+Driver.swift in Sources */,
53605369
C8F0C01B1BBBFBB9001B112F /* RxScrollViewDelegateProxy.swift in Sources */,
@@ -5506,6 +5515,7 @@
55065515
C89AB2241DAAC3350065FBE6 /* URLSession+Rx.swift in Sources */,
55075516
D203C50D1BB9C53E00D02D00 /* UISegmentedControl+Rx.swift in Sources */,
55085517
C8A81CA21E05E82C0008DEF4 /* DispatchQueue+Extensions.swift in Sources */,
5518+
C8091C591FAA39C1001DB32A /* ControlEvent+Signal.swift in Sources */,
55095519
C89AB1CC1DAAC3350065FBE6 /* ControlProperty.swift in Sources */,
55105520
D2138C861BB9BEBE00339B5C /* Observable+Bind.swift in Sources */,
55115521
AAE623771C82475700FC7801 /* UIProgressView+Rx.swift in Sources */,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// ControlEvent+Signal.swift
3+
// RxCocoa
4+
//
5+
// Created by Krunoslav Zaher on 11/1/17.
6+
// Copyright © 2017 Krunoslav Zaher. All rights reserved.
7+
//
8+
9+
import RxSwift
10+
11+
extension ControlEvent {
12+
/// Converts `ControlEvent` to `Signal` trait.
13+
///
14+
/// `ControlEvent` already can't fail, so no special case needs to be handled.
15+
public func asSignal() -> Signal<E> {
16+
return self.asSignal { (error) -> Signal<E> in
17+
#if DEBUG
18+
rxFatalError("Somehow signal received error from a source that shouldn't fail.")
19+
#else
20+
return Signal.empty()
21+
#endif
22+
}
23+
}
24+
}
25+

Sources/AllTestz/main.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,7 @@ final class SignalTests_ : SignalTests, RxTestCase {
18991899
("testSignalSharing_WhenErroring", SignalTests.testSignalSharing_WhenErroring),
19001900
("testSignalSharing_WhenCompleted", SignalTests.testSignalSharing_WhenCompleted),
19011901
("testPublishRelayAsSignal", SignalTests.testPublishRelayAsSignal),
1902+
("testControlEventAsSignal", SignalTests.testControlEventAsSignal),
19021903
("testAsSignal_onErrorJustReturn", SignalTests.testAsSignal_onErrorJustReturn),
19031904
("testAsSignal_onErrorDriveWith", SignalTests.testAsSignal_onErrorDriveWith),
19041905
("testAsSignal_onErrorRecover", SignalTests.testAsSignal_onErrorRecover),
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../RxCocoa/Traits/Signal/ControlEvent+Signal.swift

Tests/RxCocoaTests/Signal+Test.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,21 @@ extension SignalTests {
174174
XCTAssertEqual(results, [1, 2])
175175
}
176176

177+
func testControlEventAsSignal() {
178+
let hotObservable: PublishRelay<Int> = PublishRelay()
179+
let controlEvent = ControlEvent(events: hotObservable.asObservable())
180+
let xs = Signal.zip(controlEvent.asSignal(), Signal.of(0, 0)) { x, _ in
181+
return x
182+
}
183+
184+
let results = subscribeTwiceOnBackgroundSchedulerAndOnlyOneSubscription(xs, expectationFulfilled: { $0 == 2 }) {
185+
hotObservable.accept(1)
186+
hotObservable.accept(2)
187+
}
188+
189+
XCTAssertEqual(results, [1, 2])
190+
}
191+
177192
func testAsSignal_onErrorJustReturn() {
178193
let hotObservable = BackgroundThreadPrimitiveHotObservable<Int>()
179194
let xs = hotObservable.asSignal(onErrorJustReturn: -1)

0 commit comments

Comments
 (0)