createEventHook
Functions
createEventHook()
createEventHook<
T
>():EventHook
<T
>
创建事件钩子管理器
Type parameters
Parameter |
---|
T extends AnyFn |
Returns
EventHook
<T
>
Example
ts
const event = createEventHook()
const callback = () => console.log('callback run')
// on
event.on(callback)
// off
event.off(callback)
// trigger
event.trigger()
// list
event.list()
// => [callback]
// offAll
event.offAll()
event.list()
// => []
// 搭配 serialCall 改变执行流
serialCall(event.list(), ...args)
Interfaces
EventHook<T>
Type parameters
Parameter | Value |
---|---|
T extends EventHookFn | EventHookFn |
Properties
Property | Type | Description |
---|---|---|
list | () => T [] | - |
off | EventHookOff <T > | - |
offAll | EventHookOffAll | - |
on | EventHookOn <T > | - |
once | EventHookOnce <T > | - |
trigger | EventHookTrigger <T > | - |
EventHookContext<T>
Type parameters
Parameter | Value |
---|---|
T extends EventHookFn | EventHookFn |
Properties
Property | Type | Description |
---|---|---|
currentIndex | number | - |
isEnd | boolean | - |
isFirst | boolean | - |
payload | Parameters <T > | - |
returned? | ReturnType <T > | - |
Type Aliases
EventHookFn
EventHookFn:
AnyFn
EventHookOff<T>
EventHookOff<
T
>: (fn
) =>void
Type parameters
Parameter | Value |
---|---|
T extends EventHookFn | EventHookFn |
Parameters
Parameter | Type |
---|---|
fn | T |
Returns
void
EventHookOffAll
EventHookOffAll: () =>
void
Returns
void
EventHookOn<T>
EventHookOn<
T
>: (fn
) =>_EventHookOff
Type parameters
Parameter | Value |
---|---|
T extends EventHookFn | EventHookFn |
Parameters
Parameter | Type |
---|---|
fn | T |
Returns
_EventHookOff
EventHookOnce<T>
EventHookOnce<
T
>: (fn
) =>_EventHookOff
Type parameters
Parameter | Value |
---|---|
T extends EventHookFn | EventHookFn |
Parameters
Parameter | Type |
---|---|
fn | T |
Returns
_EventHookOff
EventHookTrigger<T>
EventHookTrigger<
T
>: (...args
) =>void
Type parameters
Parameter | Value |
---|---|
T extends EventHookFn | EventHookFn |
Parameters
Parameter | Type |
---|---|
...args | Parameters <T > |
Returns
void