Abstract base class for all match operation commands. Stores the minimal diff required to undo/redo: the affected match index and the before/after states of that match.

abstract class BaseCommand implements Command {
protected metadata: CommandMetadata;

constructor(
protected matchIndex: number,
protected beforeState: MangaMatchResult,
protected afterState: MangaMatchResult,
protected onExecute: OnExecuteCallback,
type: CommandType,
description: string,
) {
this.metadata = {
type,
timestamp: Date.now(),
affectedTitles: [beforeState.kenmeiManga.title],
description,
};
}

/**
* Execute the command (apply "after" state).
* @source
*/
execute(): void {
this.onExecute(this.afterState);
}

/**
* Undo the command (restore "before" state).
* @source
*/
undo(): void {
this.onExecute(this.beforeState);
}

/**
* Get user-friendly description of what this command does.
* @source
*/
getDescription(): string {
return this.metadata.description;
}

/**
* Get metadata about this command.
* @source
*/
getMetadata(): CommandMetadata {
return this.metadata;
}
}

Hierarchy (View Summary)

Implements

Constructors

Methods

  • Execute the command (apply "after" state).

    Returns void

      execute(): void {
    this.onExecute(this.afterState);
    }
  • Undo the command (restore "before" state).

    Returns void

      undo(): void {
    this.onExecute(this.beforeState);
    }
  • Get user-friendly description of what this command does.

    Returns string

      getDescription(): string {
    return this.metadata.description;
    }