forked from mcxiaoke/RxDocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mcxiaoke
committed
Jul 24, 2015
1 parent
af9328d
commit f6919e5
Showing
8 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
## Connect | ||
|
||
让一个可连接的Observable开始发射数据给订阅者 | ||
|
||
 | ||
|
||
可连接的Observable (*connectable Observable*)与普通的Observable差不多,不过它并不会在被订阅时开始发射数据,而是直到使用了`Connect`操作符时才会开始。用这个方法,你可以等待所有的观察者都订阅了Observable之后再开始发射数据。 | ||
|
||
 | ||
|
||
RxJava中`connect`是`ConnectableObservable`接口的一个方法,使用`publish`操作符可以将一个普通的Observable转换为一个`ConnectableObservable`。 | ||
|
||
调用`ConnectableObservable`的`connect`方法会让它后面的Observable开始给发射数据给订阅者。 | ||
|
||
`connect`方法返回一个`Subscription`对象,可以调用它的`unsubscribe`方法让Observable停止发射数据给观察者。 | ||
|
||
即使没有任何订阅者订阅它,你也可以使用`connect`方法让一个Observable开始发射数据(或者开始生成待发射的数据)。这样,你可以将一个"冷"的Observable变为"热"的。 | ||
|
||
* Javadoc: [connect()](http://reactivex.io/RxJava/javadoc/rx/observables/ConnectableObservable.html#connect()) | ||
* Javadoc: [connect(Action1)](http://reactivex.io/RxJava/javadoc/rx/observables/ConnectableObservable.html#connect(rx.functions.Action1)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Publish | ||
|
||
将普通的Observable换换为可连接的Observable | ||
|
||
 | ||
|
||
可连接的Observable (*connectable Observable*)与普通的Observable差不多,不过它并不会在被订阅时开始发射数据,而是直到使用了`Connect`操作符时才会开始。用这种方法,你可以在任何时候让一个Observable开始发射数据。 | ||
|
||
 | ||
|
||
RxJava的实现为`publish`。 | ||
|
||
* Javadoc: [publish()](http://reactivex.io/RxJava/javadoc/rx/Observable.html#publish()) | ||
|
||
 | ||
|
||
有一个变体接受一个函数作为参数。这个函数用原始Observable发射的数据作为参数,产生一个新的数据作为`ConnectableObservable`给发射,替换原位置的数据项。实质是在签名的基础上添加一个`Map`操作。 | ||
|
||
* Javadoc: [publish(Func1)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#publish(rx.functions.Func1)) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## RefCount | ||
|
||
让一个可连接的Observable行为像普通的Observable | ||
|
||
 | ||
|
||
可连接的Observable (*connectable Observable*)与普通的Observable差不多,不过它并不会在被订阅时开始发射数据,而是直到使用了`Connect`操作符时才会开始。用这种方法,你可以在任何时候让一个Observable开始发射数据。 | ||
|
||
`RefCount`操作符把从一个可连接的Observable连接和断开的过程自动化了。它操作一个可连接的Observable,返回一个普通的Observable。当第一个订阅者订阅这个Observable时,`RefCount`连接到下层的可连接Observable。`RefCount`跟踪有多少个观察者订阅它,直到最后一个观察者完成才断开与下层可连接Observable的连接。 | ||
|
||
 | ||
|
||
RxJava中的实现为`refCount`,还有一个操作符叫`share`,它的作用等价于对一个Observable同时应用`publish`和`refCount`操作。 | ||
|
||
* Javadoc: [refCount()](http://reactivex.io/RxJava/javadoc/rx/observables/ConnectableObservable.html#refCount()) | ||
* Javadoc: [share()](http://reactivex.io/RxJava/javadoc/rx/Observable.html#share()) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
## Replay | ||
|
||
保证所有的观察者收到相同的数据序列,即使它们在Observable开始发射数据之后才订阅 | ||
|
||
 | ||
|
||
可连接的Observable (*connectable Observable*)与普通的Observable差不多,不过它并不会在被订阅时开始发射数据,而是直到使用了`Connect`操作符时才会开始。用这种方法,你可以在任何时候让一个Observable开始发射数据。 | ||
|
||
如果在将一个Observable转换为可连接的Observable之前对它使用`Replay`操作符,产生 的这个可连接Observable将总是发射完整的数据序列给任何未来的观察者,即使那饿写观察者在这个Observable开始给其它观察者发射数据之后才订阅。 | ||
|
||
 | ||
|
||
RxJava的实现为`replay`,它有多个接受不同参数的变体,有的可以指定`replay`的最大缓存数量,有的还可以指定调度器。 | ||
|
||
* Javadoc: [replay()](http://reactivex.io/RxJava/javadoc/rx/Observable.html#replay()) | ||
* Javadoc: [replay(int)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#replay(int)) | ||
* Javadoc: [replay(long,TimeUnit)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#replay(long,%20java.util.concurrent.TimeUnit)) | ||
* Javadoc: [replay(int,long,TimeUnit)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#replay(int,%20long,%20java.util.concurrent.TimeUnit)) | ||
|
||
 | ||
|
||
有一种 `replay`返回一个普通的Observable。它可以接受一个变换函数为参数,这个函数接受原始Observable发射的数据项为参数,返回结果Observable要发射的一项数据。因此,这个操作符其实是`replay`变换之后的数据项。 | ||
|
||
* Javadoc: [replay(Func1)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#replay(rx.functions.Func1)) | ||
* Javadoc: [replay(Func1,int)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#replay(rx.functions.Func1,%20int)) | ||
* Javadoc: [replay(Func1,long,TimeUnit)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#replay(rx.functions.Func1,%20long,%20java.util.concurrent.TimeUnit)) | ||
* Javadoc: [replay(Func1,int,long,TimeUnit)](http://reactivex.io/RxJava/javadoc/rx/Observable.html#replay(rx.functions.Func1,%20int,%20long,%20java.util.concurrent.TimeUnit)) | ||
|
||
|