Skip to content

Commit

Permalink
docs(subscription): translate source subscription.md<100%>
Browse files Browse the repository at this point in the history
  • Loading branch information
SangKa committed May 25, 2017
1 parent 5dc172a commit c7ee74f
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions doc/subscription.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Subscription
# Subscription (订阅)

**What is a Subscription?** A Subscription is an object that represents a disposable resource, usually the execution of an Observable. A Subscription has one important method, `unsubscribe`, that takes no argument and just disposes the resource held by the subscription. In previous versions of RxJS, Subscription was called "Disposable".
**什么是 Subscription** - Subscription 是表示可清理资源的对象,通常是 Observable 的执行。Subscription 有一个重要的方法,即 `unsubscribe`,它不需要任何参数,只是用来清理由 Subscription 占用的资源。在上一个版本的 RxJS 中,Subscription 叫做 "Disposable" (可清理对象)。

```js
var observable = Rx.Observable.interval(1000);
var subscription = observable.subscribe(x => console.log(x));
// Later:
// This cancels the ongoing Observable execution which
// was started by calling subscribe with an Observer.
// 稍后:
// 这会取消正在进行中的 Observable 执行
// Observable 执行是通过使用观察者调用 subscribe 方法启动的
subscription.unsubscribe();
```

<span class="informal">A Subscription essentially just has an `unsubscribe()` function to release resources or cancel Observable executions.</span>
<span class="informal"> Subscription 基本上只有一个 `unsubscribe()` 函数,这个函数用来释放资源或去取消 Observable 执行。</span>

Subscriptions can also be put together, so that a call to an `unsubscribe()` of one Subscription may unsubscribe multiple Subscriptions. You can do this by "adding" one subscription into another:
Subscription 还可以合在一起,这样一个 Subscription 调用 `unsubscribe()` 方法,可能会有多个 Subscription 取消订阅 。你可以通过把一个 Subscription 添加到另一个上面来做这件事:

```js
var observable1 = Rx.Observable.interval(400);
Expand All @@ -25,12 +25,13 @@ var childSubscription = observable2.subscribe(x => console.log('second: ' + x));
subscription.add(childSubscription);

setTimeout(() => {
// Unsubscribes BOTH subscription and childSubscription
// subscription childSubscription 都会取消订阅
subscription.unsubscribe();
}, 1000);
```

When executed, we see in the console:
执行时,我们在控制台中看到:

```none
second: 0
first: 0
Expand All @@ -39,4 +40,4 @@ first: 1
second: 2
```

Subscriptions also have a `remove(otherSubscription)` method, in order to undo the addition of a child Subscription.
Subscriptions 还有一个 `remove(otherSubscription)` 方法,用来撤销一个已添加的子 Subscription

0 comments on commit c7ee74f

Please sign in to comment.