Skip to content
This repository was archived by the owner on Aug 8, 2022. It is now read-only.

docs: translate effect-scope.md #655

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/api/effect-scope.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<!-- TODO: translation -->
# Effect Scope API <Badge text="3.2+" />

:::info
Effect scope is an advanced API primarily intended for library authors. For details on how to leverage this API, please consult its corresponding [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md).
Effect scope 主要面向于库作者的高级 API。关于如何利用此 API 的详细信息,请参阅相应的 [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md)
:::

## `effectScope`

Creates an effect scope object which can capture the reactive effects (e.g. computed and watchers) created within it so that these effects can be disposed together.
创建一个副作用范围对象,它可以捕获在其中创建的响应式副作用 (例如:computed 和 watcher),便于把这些副作用一起处理。

**Typing:**
**类型:**

```ts
function effectScope(detached?: boolean): EffectScope
Expand All @@ -20,7 +19,7 @@ interface EffectScope {
}
```

**Example:**
**案例:**

```js
const scope = effectScope()
Expand All @@ -33,27 +32,27 @@ scope.run(() => {
watchEffect(() => console.log('Count: ', doubled.value))
})

// to dispose all effects in the scope
// 处理 scope 中的所有副作用
scope.stop()
```

## `getCurrentScope`

Returns the current active [effect scope](#effectscope) if there is one.
如果有当前活动的 [effect scope](#effectscope),就返回它。

**Typing:**
**类型:**

```ts
function getCurrentScope(): EffectScope | undefined
```

## `onScopeDispose`

Registers a dispose callback on the current active [effect scope](#effectscope). The callback will be invoked when the associated effect scope is stopped.
在当前活动的 [effect scope](#effectscope) 上注册一个处理回调。该回调会在其关联的副作用范围停止的时候被调用。

This method can be used as a non-component-coupled replacement of `onUnmounted` in reusable composition functions, since each Vue component's `setup()` function is also invoked in an effect scope.
这个方法可以在可复用的组合函数中 `onUnmounted` 的一个非组件耦合替代品,因为每个

**Typing:**
**类型:**

```ts
function onScopeDispose(fn: () => void): void
Expand Down