Skip to content

Commit

Permalink
docs: 更新 taro events 文章
Browse files Browse the repository at this point in the history
  • Loading branch information
ruochuan12 committed Aug 28, 2024
1 parent c65a6ea commit f299185
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/taro/events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,23 +598,27 @@ export class TaroHooks<T extends Record<string, TFunc> = any> extends Events {
}
```

### 8.1 tap 实现
### 8.1 tap 方法 - 监听事件

```ts
tap<K extends Extract<keyof T, string>> (hookName: K, callback: T[K] | T[K][]) {
const hooks = this.hooks
const { type, initial } = hooks[hookName]
if (type === HOOK_TYPE.SINGLE) {
// 单个类型的hook,则取消监听事件,重新监听事件
this.off(hookName)
this.on(hookName, isFunction(callback) ? callback : callback[callback.length - 1])
} else {
// 不是,则取消监听指定回调函数的事件,重新监听一个或多个事件
initial && this.off(hookName, initial)
this.tapOneOrMany(hookName, callback)
}
}
```

### 8.2 call 实现
`tap` 方法是监听事件,`hook`类型是`SINGLE`类型时,直接取消,重新监听。不是`SINGLE`类型时,则取消监听指定回调函数的事件,重新监听一个或多个事件。

### 8.2 call 方法 - 触发事件

```ts
call<K extends Extract<keyof T, string>> (hookName: K, ...rest: Parameters<T[K]>): ReturnType<T[K]> | undefined {
Expand Down

0 comments on commit f299185

Please sign in to comment.