mirror of
https://github.com/ReactiveX/RxSwift.git
synced 2024-10-05 06:27:29 +03:00
Playground: Working with Subjects, Remove Variable
This commit is contained in:
parent
dbbb81115e
commit
62419d6648
@ -179,7 +179,7 @@ example("skip") {
|
||||
*/
|
||||
example("skipWhile") {
|
||||
let disposeBag = DisposeBag()
|
||||
|
||||
|
||||
Observable.of(1, 2, 3, 4, 5, 6)
|
||||
.skipWhile { $0 < 4 }
|
||||
.subscribe(onNext: { print($0) })
|
||||
|
@ -89,22 +89,6 @@ example("BehaviorSubject") {
|
||||
}
|
||||
/*:
|
||||
> Notice what's missing in these previous examples? A Completed event. `PublishSubject`, `ReplaySubject`, and `BehaviorSubject` do not automatically emit Completed events when they are about to be disposed of.
|
||||
----
|
||||
## Variable
|
||||
Wraps a `BehaviorSubject`, so it will emit the most recent (or initial) value to new subscribers. And `Variable` also maintains current value state. `Variable` will never emit an Error event. However, it will automatically emit a Completed event and terminate on `deinit`.
|
||||
*/
|
||||
example("Variable") {
|
||||
let disposeBag = DisposeBag()
|
||||
let variable = Variable("🔴")
|
||||
|
||||
variable.asObservable().addObserver("1").disposed(by: disposeBag)
|
||||
variable.value = "🐶"
|
||||
variable.value = "🐱"
|
||||
|
||||
variable.asObservable().addObserver("2").disposed(by: disposeBag)
|
||||
variable.value = "🅰️"
|
||||
variable.value = "🅱️"
|
||||
}
|
||||
//: > Call `asObservable()` on a `Variable` instance in order to access its underlying `BehaviorSubject` sequence. `Variable`s do not implement the `on` operator (or, e.g., `onNext(_:)`), but instead expose a `value` property that can be used to get the current value, and also set a new value. Setting a new value will also add that value onto its underlying `BehaviorSubject` sequence.
|
||||
|
||||
//: [Next](@next) - [Table of Contents](Table_of_Contents)
|
||||
|
Loading…
Reference in New Issue
Block a user