Options
All
  • Public
  • Public/Protected
  • All
Menu

Class InterceptedCommand

Implements a command wrapped by an interceptor. It allows to build command call chains. The interceptor can alter execution and delegate calls to a next command, which can be intercepted or concrete.

see

ICommand

see

ICommandInterceptor

Example

export class CommandLogger implements ICommandInterceptor {

    public getName(command: ICommand): string {
        return command.getName();
    }

    public execute(correlationId: string, command: ICommand, args: Parameters, callback: (err: any, result: any) => void): void {
        console.log("Executed command " + command.getName());
        command.execute(correlationId, args, callback);
    }

    private validate(command: ICommand, args: Parameters): ValidationResult[] {
        return command.validate(args);
    }
}

let logger = new CommandLogger();
let loggedCommand = new InterceptedCommand(logger, command);

// Each called command will output: Executed command <command name>

Hierarchy

  • InterceptedCommand

Implements

Index

Constructors

Methods

Constructors

constructor

  • Creates a new InterceptedCommand, which serves as a link in an execution chain. Contains information about the interceptor that is being used and the next command in the chain.

    Parameters

    • interceptor: ICommandInterceptor

      the interceptor that is intercepting the command.

    • next: ICommand

      (link to) the next command in the command's execution chain.

    Returns InterceptedCommand

Methods

execute

  • execute(correlationId: string, args: Parameters, callback: function): void
  • Executes the next command in the execution chain using the given parameters (arguments).

    see

    Parameters

    Parameters

    • correlationId: string

      unique transaction id to trace calls across components.

    • args: Parameters

      the parameters (arguments) to pass to the command for execution.

    • callback: function

      the function that is to be called once execution is complete. If an exception is raised, then it will be called with the error.

        • (err: any, result: any): void
        • Parameters

          • err: any
          • result: any

          Returns void

    Returns void

getName

  • getName(): string

validate

Generated using TypeDoc