DispatcherPayloadMeta

Interface

export interface Transaction {
    readonly name: string;
}
export interface DispatcherPayloadMeta {
    readonly useCase: UseCaseLike | null;
    readonly dispatcher: UseCase | Dispatcher | null;
    readonly parentUseCase: UseCase | Dispatcher | null;
    readonly timeStamp: number;
    readonly isTrusted: boolean;
    readonly isUseCaseFinished: boolean;
    transaction?: Transaction;
}

Interface

export interface Transaction {
    readonly name: string;

Transaction data structure


export interface DispatcherPayloadMeta {

DispatcherPayloadMeta is a meta object for payload.

When Dispatcher dispatch payload with DispatcherPayloadMeta instance object.

const dispatcher = new Dispatcher();
dispatcher.onDispatch((payload, meta) => {
   console.log(meta); // instance of DispatcherPayloadMeta
   console.log(meta.useCase); // reference to UseCase
   console.log(meta.parentUseCase); // reference to Parent UseCase
   console.log(meta.dispatcher); // reference to Dispatcher
   console.log(meta.timeStamp); // Timestamp
   console.log(meta.isTrusted); // Is it system payload?
});

readonly useCase: UseCaseLike | null;

A reference to the useCase/dispatcher to which the payload was originally dispatched.


readonly dispatcher: UseCase | Dispatcher | null;

A dispatcher of the payload In other word, the payload is dispatched by this.dispatcher

Dispatcher in a useCase

In following example, this.dispatcher is same with this.useCase.

class Example extends UseCase {
    execute(){
       this.dispatch({ type })
    // ^^^^
    // === this dispatcher === this.useCase
    }
}

readonly parentUseCase: UseCase | Dispatcher | null;

A parent useCase of the this.useCase, When useCase is nesting, parentUseCase is a UseCase.


readonly timeStamp: number;

A timeStamp is created time of the meta.


readonly isTrusted: boolean;

If the payload object is generated by Almin, true.

The use can use it for detecting "Is the payload generated by system(almin)?". It is similar with https://www.w3.org/TR/DOM-Level-3-Events/#trusted-events


readonly isUseCaseFinished: boolean;

If the useCase is finished, return true. Most of useCase is fixed value. But, DidExecutedPayload's value is case by case. In DidExecutedPayload, the value is false if the UseCase#execute return a promise. See https://github.com/almin/almin/issues/149


transaction?: Transaction;

If the payload object is dispatched in a transaction, to be transaction object otherwise, to be undefined


results matching ""

    No results matching ""