Line data Source code
1 : import type { Command, Direction } from '#/history'
2 :
3 2 : export class PropCommand<T> implements Command {
4 : constructor(
5 0 : readonly label: string,
6 0 : readonly dirtyMask: number,
7 : _get: () => T,
8 0 : private readonly set: (v: T) => void,
9 0 : private readonly before: T,
10 0 : private after: T,
11 0 : private readonly mergeKey?: string
12 : ) {}
13 :
14 : apply(dir: Direction): void {
15 0 : this.set(dir === 'undo' ? this.before : this.after)
16 : }
17 :
18 : sizeBytes(): number {
19 0 : return 64
20 : }
21 :
22 : tryMerge(prev: Command): boolean {
23 0 : if (
24 : this.mergeKey !== undefined &&
25 : prev instanceof PropCommand &&
26 : prev.mergeKey === this.mergeKey
27 : ) {
28 0 : prev.after = this.after as never
29 0 : return true
30 : }
31 0 : return false
32 : }
33 : }
|