Command for bulk updates to match results. Applies an array of match results as a single atomic operation. Useful for batch operations where the entire state is replaced at once. This avoids triggering multiple re-renders by using a single updateMatchResults call.

export class BulkUpdateCommand implements Command {
private readonly metadata: CommandMetadata;

constructor(
private readonly beforeState: MangaMatchResult[],
private readonly afterState: MangaMatchResult[],
private readonly onExecute: OnBulkExecuteCallback,
description: string = "Bulk update",
) {
// Collect all affected titles from the after state
const affectedTitles = afterState
.filter((result, idx) => {
const before = beforeState[idx];
return before && before.status !== result.status;
})
.map((r) => r.kenmeiManga.title);

this.metadata = {
type: CommandType.BATCH_OPERATION,
timestamp: Date.now(),
affectedTitles,
description,
};
}

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

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

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

getMetadata(): CommandMetadata {
return this.metadata;
}
}

Implements

Constructors

Methods