Skip to content

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

ParameterValue
T extends EventHookFnEventHookFn

Properties

PropertyTypeDescription
list() => T[]-
offEventHookOff<T>-
offAllEventHookOffAll-
onEventHookOn<T>-
onceEventHookOnce<T>-
triggerEventHookTrigger<T>-

EventHookContext<T>

Type parameters

ParameterValue
T extends EventHookFnEventHookFn

Properties

PropertyTypeDescription
currentIndexnumber-
isEndboolean-
isFirstboolean-
payloadParameters<T>-
returned?ReturnType<T>-

Type Aliases

EventHookFn

EventHookFn: AnyFn


EventHookOff<T>

EventHookOff<T>: (fn) => void

Type parameters

ParameterValue
T extends EventHookFnEventHookFn

Parameters

ParameterType
fnT

Returns

void


EventHookOffAll

EventHookOffAll: () => void

Returns

void


EventHookOn<T>

EventHookOn<T>: (fn) => _EventHookOff

Type parameters

ParameterValue
T extends EventHookFnEventHookFn

Parameters

ParameterType
fnT

Returns

_EventHookOff


EventHookOnce<T>

EventHookOnce<T>: (fn) => _EventHookOff

Type parameters

ParameterValue
T extends EventHookFnEventHookFn

Parameters

ParameterType
fnT

Returns

_EventHookOff


EventHookTrigger<T>

EventHookTrigger<T>: (...args) => void

Type parameters

ParameterValue
T extends EventHookFnEventHookFn

Parameters

ParameterType
...argsParameters<T>

Returns

void