Skip to content

Effect Scope API の翻訳 #492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2021
Merged
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
24 changes: 12 additions & 12 deletions src/api/effect-scope.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
# Effect Scope API <Badge text="3.2+" />
# エフェクトスコープ 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).
エフェクトスコープは、主にライブラリの作成者を対象とした高度な 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

interface EffectScope {
run<T>(fn: () => T): T | undefined // undefined if scope is inactive
run<T>(fn: () => T): T | undefined // スコープが非アクティブの場合は undefined
stop(): void
}
```

**Example:**
**:**

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

// to dispose all effects in the scope
// スコープ内のすべてのエフェクトを破棄する
scope.stop()
```

## `getCurrentScope`

Returns the current active [effect scope](#effectscope) if there is one.
現在アクティブな[エフェクトスコープ](#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.
現在アクティブな[エフェクトスコープ](#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.
このメソッドは、各 Vue コンポーネントの `setup()` 関数もエフェクトスコープで呼び出すため、再利用可能に構成された関数の `onUnmounted` の非結合コンポーネントの代替として使用できます。

**Typing:**
**タイピング:**

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