Class: Action<ARG, DATA>

Type parameters

Name Type
ARG ARG
DATA void

Table of contents

Constructors

Properties

Accessors

Methods

Constructors

constructor

new Action<ARG, DATA>(actionExecutor, scope?)

Type parameters

Name Type
ARG ARG
DATA void

Parameters

Name Type
actionExecutor (args: ARG) => PromiseOrValue<ActionExecutorReturnType<DATA>>
scope? Scope

Properties

_arg

Private _arg: any

最近一次执行的参数,目前还没有增加自动清理机制,有很小可能会造成内存泄漏


_error

Private _error: any


_state

Private _state: any


actionExecutor

Private Readonly actionExecutor: any


eventFailedTriggers

Private Readonly eventFailedTriggers: any


eventSuccessTriggers

Private Readonly eventSuccessTriggers: any


scope

Private Readonly scope: any


setFailed

Private setFailed: any


setResult

Private setResult: any


triggerEvents

Private triggerEvents: any

Accessors

arg

get arg(): undefined | ARG

Returns

undefined | ARG


error

get error(): unknown

Returns

unknown


isFailed

get isFailed(): boolean

Returns

boolean


isRunning

get isRunning(): boolean

Returns

boolean


state

get state(): ActionState

Returns

ActionState

Methods

run

run(...args): boolean | Promise<boolean>

Parameters

Name Type
...args ARG extends void ? [] : [ARG]

Returns

boolean | Promise<boolean>


runOn

runOn<EVENT>(eventRegistry, mapper, filter?): () => void

将当前的Action与一个事件关联起来。当事件触发时,将执行此Action。

Type parameters

Name
EVENT

Parameters

Name Type Description
eventRegistry EventRegistry<EVENT> 事件注册器
mapper (event: EVENT) => ARG 事件到Action参数的映射函数
filter? (event: EVENT) => boolean 事件过滤函数,返回false表示不执行Action

Returns

fn

取消函数

(): void

将当前的Action与一个事件关联起来。当事件触发时,将执行此Action。

Returns

void

取消函数


triggersDoneEvent

triggersDoneEvent(eventSource, condition?): void

Parameters

Name Type
eventSource EventRegistry<DATA>
condition? (data: DATA) => boolean

Returns

void


triggersDoneEventWithMapper

triggersDoneEventWithMapper<EVENT>(eventSource, mapper, condition?): void

Type parameters

Name
EVENT

Parameters

Name Type
eventSource EventRegistry<EVENT>
mapper (data: DATA, arg: ARG) => EVENT
condition? (data: DATA) => boolean

Returns

void


triggersFailedEvent

triggersFailedEvent<T>(eventSource, mapper, condition?): void

Type parameters

Name
T

Parameters

Name Type
eventSource EventRegistry<T>
mapper (reason: unknown, arg: ARG) => T
condition? (reason: unknown) => boolean

Returns

void