Skip to content

Commit 17c2492

Browse files
committed
Deprecates shareReplayLatestWhileConnected and shareReplay.
1 parent 610c3f7 commit 17c2492

File tree

2 files changed

+40
-39
lines changed

2 files changed

+40
-39
lines changed

RxSwift/Deprecated.swift

+39
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,42 @@ extension Disposable {
112112
disposed(by: bag)
113113
}
114114
}
115+
116+
117+
extension ObservableType {
118+
119+
/**
120+
Returns an observable sequence that shares a single subscription to the underlying sequence, and immediately upon subscription replays latest element in buffer.
121+
122+
This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
123+
124+
- seealso: [shareReplay operator on reactivex.io](http://reactivex.io/documentation/operators/replay.html)
125+
126+
- returns: An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
127+
*/
128+
@available(*, deprecated, message: "use share(replay: 1) instead", renamed: "share(replay:)")
129+
public func shareReplayLatestWhileConnected()
130+
-> Observable<E> {
131+
return share(replay: 1, scope: .whileConnected)
132+
}
133+
}
134+
135+
136+
extension ObservableType {
137+
138+
/**
139+
Returns an observable sequence that shares a single subscription to the underlying sequence, and immediately upon subscription replays maximum number of elements in buffer.
140+
141+
This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
142+
143+
- seealso: [shareReplay operator on reactivex.io](http://reactivex.io/documentation/operators/replay.html)
144+
145+
- parameter bufferSize: Maximum element count of the replay buffer.
146+
- returns: An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
147+
*/
148+
@available(*, deprecated, message: "Suggested replacement is `share(replay: 1)`. In case old 3.x behavior of `shareReplay` is required please use `share(replay: 1, scope: .forever)` instead.", renamed: "share(replay:)")
149+
public func shareReplay(_ bufferSize: Int)
150+
-> Observable<E> {
151+
return self.share(replay: bufferSize, scope: .forever)
152+
}
153+
}

RxSwift/Observables/ShareReplayScope.swift

+1-39
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ extension ObservableType {
144144
case .forever:
145145
switch replay {
146146
case 0: return self.multicast(PublishSubject()).refCount()
147-
default: return shareReplay(replay)
147+
default: return self.multicast(ReplaySubject.create(bufferSize: replay)).refCount()
148148
}
149149
case .whileConnected:
150150
switch replay {
@@ -156,44 +156,6 @@ extension ObservableType {
156156
}
157157
}
158158

159-
extension ObservableType {
160-
161-
/**
162-
Returns an observable sequence that shares a single subscription to the underlying sequence, and immediately upon subscription replays latest element in buffer.
163-
164-
This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
165-
166-
Unlike `shareReplay(bufferSize: Int)`, this operator will clear latest element from replay buffer in case number of subscribers drops from one to zero. In case sequence
167-
completes or errors out replay buffer is also cleared.
168-
169-
- seealso: [shareReplay operator on reactivex.io](http://reactivex.io/documentation/operators/replay.html)
170-
171-
- returns: An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
172-
*/
173-
public func shareReplayLatestWhileConnected()
174-
-> Observable<E> {
175-
return ShareReplay1WhileConnected(source: self.asObservable())
176-
}
177-
}
178-
179-
extension ObservableType {
180-
181-
/**
182-
Returns an observable sequence that shares a single subscription to the underlying sequence, and immediately upon subscription replays maximum number of elements in buffer.
183-
184-
This operator is a specialization of replay which creates a subscription when the number of observers goes from zero to one, then shares that subscription with all subsequent observers until the number of observers returns to zero, at which point the subscription is disposed.
185-
186-
- seealso: [shareReplay operator on reactivex.io](http://reactivex.io/documentation/operators/replay.html)
187-
188-
- parameter bufferSize: Maximum element count of the replay buffer.
189-
- returns: An observable sequence that contains the elements of a sequence produced by multicasting the source sequence.
190-
*/
191-
public func shareReplay(_ bufferSize: Int)
192-
-> Observable<E> {
193-
return self.replay(bufferSize).refCount()
194-
}
195-
}
196-
197159
fileprivate final class ShareReplay1WhileConnectedConnection<Element>
198160
: ObserverType
199161
, SynchronizedUnsubscribeType {

0 commit comments

Comments
 (0)