-
-
Notifications
You must be signed in to change notification settings - Fork 175
/
CommandsIterable.ts
25 lines (24 loc) · 1008 Bytes
/
CommandsIterable.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { cloneMethod } from '../../symbols';
import { CommandWrapper } from './CommandWrapper';
/** @hidden */
export class CommandsIterable<Model extends object, Real, RunResult, CheckAsync extends boolean = false>
implements Iterable<CommandWrapper<Model, Real, RunResult, CheckAsync>> {
constructor(
readonly commands: CommandWrapper<Model, Real, RunResult, CheckAsync>[],
readonly metadataForReplay: () => string
) {}
[Symbol.iterator](): Iterator<CommandWrapper<Model, Real, RunResult, CheckAsync>> {
return this.commands[Symbol.iterator]();
}
[cloneMethod]() {
return new CommandsIterable(this.commands.map(c => c.clone()), this.metadataForReplay);
}
toString(): string {
const serializedCommands = this.commands
.filter(c => c.hasRan)
.map(c => c.toString())
.join(',');
const metadata = this.metadataForReplay();
return metadata.length !== 0 ? `${serializedCommands} /*${metadata}*/` : serializedCommands;
}
}