Skip to content

Commit 643ec42

Browse files
authored
Update How-To-Use-RxJava.md
修改文字错误···“对象属猪”-->“对象属性”
1 parent 7c0cf09 commit 643ec42

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

topics/How-To-Use-RxJava.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
* [RxGroovy 示例](https://github.com/ReactiveX/RxGroovy/tree/1.x/src/examples/groovy/rx/lang/groovy/examples)
66
* [RxClojure 示例](https://github.com/ReactiveX/RxClojure/tree/0.x/src/examples/clojure/rx/lang/clojure/examples)
7-
* [RxScala 示例](https://github.com/ReactiveX/RxScala/tree/0.x/examples/src/main/scala)
8-
7+
* [RxScala 示例](https://github.com/ReactiveX/RxScala/tree/0.x/examples/src/main/scala)
8+
99
下面的示例从一个字符串列表创建一个Observable,然后使用一个方法订阅这个Observable。
1010

1111
### Java
@@ -76,16 +76,16 @@ Hello George!
7676
```
7777

7878
# 如何使用RxJava
79-
79+
8080
要使用RxJava,首先你需要创建Observable(它们发射数据序列),使用Observable操作符变换那些Observables,获取严格符合你要求的数据,然后观察并处理对这些数据序列(通过实现观察者或订阅者,然后订阅变换后的Observable)。
8181

8282
## 创建Observables
83-
83+
8484
要创建Observable,你可以手动实现Observable的行为,也可以传递一个函数给[`create( )`](../operators/Create.md),还可以使用这些 [创建操作符](../operators/Creating-Observables.md) 将一个已有的数据结构转换为Observable。
8585

8686
### 已有的数据结构创建Observable
87-
88-
你可以使用[`just( )`](../operators/Just.md)[`from( )`](../operators/From.md) 方法将对象,列表,对象属猪转换为发射那些对象的Observable
87+
88+
你可以使用[`just( )`](../operators/Just.md)[`from( )`](../operators/From.md) 方法将对象,列表,对象属性转换为发射那些对象的Observable
8989

9090
```java
9191
Observable<String> o = Observable.from("a", "b", "c");
@@ -95,7 +95,7 @@ Observable<Integer> o = Observable.from(list);
9595

9696
Observable<String> o = Observable.just("one object");
9797
```
98-
98+
9999
转换后的Observable每发射一项数据,会同步地调用任何订阅者的[`onNext()`](../Observables.md#回调方法)方法,最后会调用订阅者的[`onCompleted()`](../Observables.md#回调方法)方法。
100100

101101
### 使用`create( )`创建一个Observable
@@ -105,7 +105,7 @@ Observable<String> o = Observable.just("one object");
105105
#### 同步的Observable示例
106106

107107
```groovy
108-
/**
108+
/**
109109
* 这个例子展示了一个自定义的Observable,当有订阅时他会阻塞当前线程。
110110
*/
111111
def customObservableBlocking() {
@@ -128,9 +128,9 @@ customObservableBlocking().subscribe { println(it) }
128128

129129
#### 异步的Observable示例
130130

131-
The following example uses Groovy to create an Observable that emits 75 strings.
131+
The following example uses Groovy to create an Observable that emits 75 strings.
132132
下面的例子使用`Groovy`创建了一个发射75个字符串的Observable。
133-
133+
134134
为了让它更清楚,例子很详细,使用静态类型和匿名内部类`Func1`
135135

136136
```groovy
@@ -158,7 +158,7 @@ def customObservableNonBlocking() {
158158
// To see output:
159159
customObservableNonBlocking().subscribe { println(it) }
160160
```
161-
161+
162162
这是一个用`Clojure`写的例子,使用Future(而不是直接用线程),实现很简洁:
163163

164164
```clojure
@@ -181,7 +181,7 @@ customObservableNonBlocking().subscribe { println(it) }
181181
; To see output
182182
(.subscribe (customObservableNonBlocking) #(println %))
183183
```
184-
184+
185185
这个例子从维基百科网站抓取文章,每抓取一篇会调用一次`onNext`:
186186

187187
```clojure
@@ -203,7 +203,7 @@ customObservableNonBlocking().subscribe { println(it) }
203203
(-> (fetchWikipediaArticleAsynchronously ["Tiger" "Elephant"])
204204
(.subscribe #(println "--- Article ---\n" (subs (:body %) 0 125) "...")))
205205
```
206-
206+
207207
回到`Groovy`,同样是从维基百科抓取文章,这儿使用闭包代替匿名内部类:
208208

209209
```groovy
@@ -248,18 +248,18 @@ fetchWikipediaArticleAsynchronously("Tiger", "Elephant")
248248

249249
Note that all of the above examples ignore error handling, for brevity. See below for examples that include error handling.
250250

251-
More information can be found on the [[Observable]] and [[Creating Observables|Creating-Observables]] pages.
252-
253-
注意:为了简洁,上面的所有例子都忽略了错误处理,查看下面包含错误处理的例子。
254-
251+
More information can be found on the [[Observable]] and [[Creating Observables|Creating-Observables]] pages.
252+
253+
注意:为了简洁,上面的所有例子都忽略了错误处理,查看下面包含错误处理的例子。
254+
255255
更多的信息可以在这里找到:[`Observable`](Observables.md) 和 [`Creating Observables`](../operators/Creating-Observables.md)。
256256

257257
## 使用变换操作
258-
258+
259259
RxJava让你可以链式使用`操作符`用来转换和组合多个Observables。
260260

261-
The following example, in Groovy, uses a previously defined, asynchronous Observable that emits 75 items, skips over the first 10 of these ([`skip(10)`](http://reactivex.io/documentation/operators/skip.html)), then takes the next 5 ([`take(5)`](http://reactivex.io/documentation/operators/take.html)), and transforms them ([`map(...)`](http://reactivex.io/documentation/operators/map.html)) before subscribing and printing the items:
262-
261+
The following example, in Groovy, uses a previously defined, asynchronous Observable that emits 75 items, skips over the first 10 of these ([`skip(10)`](http://reactivex.io/documentation/operators/skip.html)), then takes the next 5 ([`take(5)`](http://reactivex.io/documentation/operators/take.html)), and transforms them ([`map(...)`](http://reactivex.io/documentation/operators/map.html)) before subscribing and printing the items:
262+
263263
下面是一个`Groovy`的例子,使用之前的定义,它会异步发射75个字符串,跳过最开始的10个(([`skip(10)`](../operators/Skip.md)),然后获取接下来的5个([`take(5)`](../operators/Taks.md)),在订阅之前使用[`map()`](../operators/Map.md)转换它们,然后打印结果字符串。
264264

265265
```groovy
@@ -283,11 +283,11 @@ onNext => value_12_xform
283283
onNext => value_13_xform
284284
onNext => value_14_xform
285285
```
286-
286+
287287
这里有一个图例解释了转换过程:
288288

289289
<img src="../images/operators/Composition.1.png" width="640" height="536" />
290-
290+
291291
这一个例子使用`Clojure`,使用了三个异步的Observable,其中一个依赖另一个,使用[`zip`](../operators/Zip.md)组合这三个发射的数据项为一个单个数据项,最后使用[`map()`](../operators/Map.md)转换这个结果:
292292

293293
```clojure
@@ -331,13 +331,13 @@ onNext => value_14_xform
331331
:director David Fincher, :duration 3365},
332332
:user-id 12345, :language es-us, :bookmark 0}
333333
```
334-
334+
335335
这里有一个图例解释了这个过程:
336336

337337
<img src="../images/operators/Composition.2.png" width="640" height="742" />
338338

339-
The following example, in Groovy, comes from [Ben Christensen’s QCon presentation on the evolution of the Netflix API](https://speakerdeck.com/benjchristensen/evolution-of-the-netflix-api-qcon-sf-2013). It combines two Observables with the [`merge`](http://reactivex.io/documentation/operators/merge.html) operator, then uses the [`reduce`](http://reactivex.io/documentation/operators/reduce.html) operator to construct a single item out of the resulting sequence, then transforms that item with [`map`](http://reactivex.io/documentation/operators/map.html) before emitting it:
340-
339+
The following example, in Groovy, comes from [Ben Christensen’s QCon presentation on the evolution of the Netflix API](https://speakerdeck.com/benjchristensen/evolution-of-the-netflix-api-qcon-sf-2013). It combines two Observables with the [`merge`](http://reactivex.io/documentation/operators/merge.html) operator, then uses the [`reduce`](http://reactivex.io/documentation/operators/reduce.html) operator to construct a single item out of the resulting sequence, then transforms that item with [`map`](http://reactivex.io/documentation/operators/map.html) before emitting it:
340+
341341
下面的例子使用`Groovy`,来自这里 [Ben Christensen’s QCon presentation on the evolution of the Netflix API](https://speakerdeck.com/benjchristensen/evolution-of-the-netflix-api-qcon-sf-2013),它使用[`merge`](../operators/Merge.md)操作结合两个Observables,使用[`reduce`](../operators/Reduce.md)操作符从结果序列构建一个单独的结果数据项,然后在发射之前,使用[`map()`](../operators/Map.md)变换那个结果。
342342

343343
```groovy
@@ -350,13 +350,13 @@ public Observable getVideoSummary(APIVideo video) {
350350
.map({ [(video.id.toString() : it] }))
351351
}
352352
```
353-
353+
354354
这里也有一个图例解释[`reduce`](../operators/Reduce.md)从多个Observable的结果构建一个单一结构的过程:
355355

356-
<img src="../images/operators/Composition.3.png" width="640" height="640" />
356+
<img src="../images/operators/Composition.3.png" width="640" height="640" />
357357

358358
## 错误处理
359-
359+
360360
这里是另一个版本的维基百科的例子,包含错误处理代码:
361361

362362
```groovy
@@ -386,7 +386,7 @@ def fetchWikipediaArticleAsynchronouslyWithErrorHandling(String... wikipediaArti
386386
});
387387
}
388388
```
389-
389+
390390
下面的例子使用`Groovy`,注意错误发生时现在是如何调用[`onError(Throwable t)`](Observables.md#回调函数)的,下面的代码传递给[`subscribe()`](../operators/Subscribe.md)第二个方法用户处理`onError`通知:
391391

392392
```groovy
@@ -396,7 +396,7 @@ fetchWikipediaArticleAsynchronouslyWithErrorHandling("Tiger", "NonExistentTitle"
396396
{ println "--- Error ---\n" + it.getMessage() })
397397
```
398398

399-
399+
400400
查看 [`错误处理操作符`](../operators/Error-Handling-Operators.md) 这一夜了解更多RxJava中的错误处理技术,包括使用 [`onErrorResumeNext()`和`onErrorReturn()`](../operators/Catch.md)等方法,它们让你可以从错误中恢复。
401401

402402
这里是一个`Groovy`的例子:
@@ -406,4 +406,4 @@ myModifiedObservable = myObservable.onErrorResumeNext({ t ->
406406
Throwable myThrowable = myCustomizedThrowableCreator(t);
407407
return (Observable.error(myThrowable));
408408
});
409-
```
409+
```

0 commit comments

Comments
 (0)