forked from ReactiveX/RxSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeprecated.swift
134 lines (111 loc) · 4.53 KB
/
Deprecated.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// Deprecated.swift
// RxCocoa
//
// Created by Krunoslav Zaher on 3/19/17.
// Copyright © 2017 Krunoslav Zaher. All rights reserved.
//
#if !RX_NO_MODULE
import RxSwift
#endif
extension ObservableType {
/**
Creates new subscription and sends elements to observer.
In this form it's equivalent to `subscribe` method, but it communicates intent better, and enables
writing more consistent binding code.
- parameter observer: Observer that receives events.
- returns: Disposable object that can be used to unsubscribe the observer.
*/
@available(*, deprecated, renamed: "bind(to:)")
public func bindTo<O: ObserverType>(_ observer: O) -> Disposable where O.E == E {
return self.subscribe(observer)
}
/**
Creates new subscription and sends elements to observer.
In this form it's equivalent to `subscribe` method, but it communicates intent better, and enables
writing more consistent binding code.
- parameter observer: Observer that receives events.
- returns: Disposable object that can be used to unsubscribe the observer.
*/
@available(*, deprecated, renamed: "bind(to:)")
public func bindTo<O: ObserverType>(_ observer: O) -> Disposable where O.E == E? {
return self.map { $0 }.subscribe(observer)
}
/**
Creates new subscription and sends elements to variable.
In case error occurs in debug mode, `fatalError` will be raised.
In case error occurs in release mode, `error` will be logged.
- parameter variable: Target variable for sequence elements.
- returns: Disposable object that can be used to unsubscribe the observer.
*/
@available(*, deprecated, renamed: "bind(to:)")
public func bindTo(_ variable: Variable<E>) -> Disposable {
return subscribe { e in
switch e {
case let .next(element):
variable.value = element
case let .error(error):
let error = "Binding error to variable: \(error)"
#if DEBUG
rxFatalError(error)
#else
print(error)
#endif
case .completed:
break
}
}
}
/**
Creates new subscription and sends elements to variable.
In case error occurs in debug mode, `fatalError` will be raised.
In case error occurs in release mode, `error` will be logged.
- parameter variable: Target variable for sequence elements.
- returns: Disposable object that can be used to unsubscribe the observer.
*/
@available(*, deprecated, renamed: "bind(to:)")
public func bindTo(_ variable: Variable<E?>) -> Disposable {
return self.map { $0 as E? }.bindTo(variable)
}
/**
Subscribes to observable sequence using custom binder function.
- parameter binder: Function used to bind elements from `self`.
- returns: Object representing subscription.
*/
@available(*, deprecated, renamed: "bind(to:)")
public func bindTo<R>(_ binder: (Self) -> R) -> R {
return binder(self)
}
/**
Subscribes to observable sequence using custom binder function and final parameter passed to binder function
after `self` is passed.
public func bindTo<R1, R2>(binder: Self -> R1 -> R2, curriedArgument: R1) -> R2 {
return binder(self)(curriedArgument)
}
- parameter binder: Function used to bind elements from `self`.
- parameter curriedArgument: Final argument passed to `binder` to finish binding process.
- returns: Object representing subscription.
*/
@available(*, deprecated, renamed: "bind(to:)")
public func bindTo<R1, R2>(_ binder: (Self) -> (R1) -> R2, curriedArgument: R1) -> R2 {
return binder(self)(curriedArgument)
}
/**
Subscribes an element handler to an observable sequence.
In case error occurs in debug mode, `fatalError` will be raised.
In case error occurs in release mode, `error` will be logged.
- parameter onNext: Action to invoke for each element in the observable sequence.
- returns: Subscription object used to unsubscribe from the observable sequence.
*/
@available(*, deprecated, renamed: "bind(onNext:)")
public func bindNext(_ onNext: @escaping (E) -> Void) -> Disposable {
return subscribe(onNext: onNext, onError: { error in
let error = "Binding error: \(error)"
#if DEBUG
rxFatalError(error)
#else
print(error)
#endif
})
}
}