Skip to content

Commit 26a52e1

Browse files
committed
fix(history): renaming the delete method to be more explicit
1 parent 84945c1 commit 26a52e1

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/api/history/TreeHistory.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ export abstract class TreeHistory implements LinearHistoryBase {
146146
public abstract goTo(id: number): void;
147147

148148
/**
149-
* Deletes the targeted node. Works only if the history does not keep the
150-
* usage path (see path()).
151-
* @param id - The node ID to remove. It removes all the branch from this node.
152-
* Does not remove the branch if the current node is in it.
149+
* Deletes the targeted node and all its descendants.
150+
* Works only if the history does not keep the usage path (see path()).
151+
* @param id - The node ID to remove. It removes all the branch starting from this node included.
152+
* Does nothing if the current node is part of the nodes to be removed.
153153
*/
154-
public abstract delete(id: number): void;
154+
public abstract deleteFrom(id: number): void;
155155

156156
/**
157157
* Retrieves the modifiable attributes of the undoable node identified by the given id.

src/impl/history/TreeHistoryImpl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export class TreeHistoryImpl extends TreeHistory {
196196
this.sizePublisher.next(0);
197197
}
198198

199-
public delete(id: number): void {
199+
public deleteFrom(id: number): void {
200200
// Cannot delete if keeping path
201201
if (this.keepPath) {
202202
return;
@@ -230,7 +230,7 @@ export class TreeHistoryImpl extends TreeHistory {
230230

231231
// Cloning the array since 'delete' may alter the children list.
232232
for (const child of Array.from(node.children)) {
233-
this.delete(child.id);
233+
this.deleteFrom(child.id);
234234
}
235235

236236
if (this.currentNode === node) {

test/history/TreeHistory.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe("using a tree-based history", () => {
7777
});
7878

7979
test("delete invalid node ok", () => {
80-
history.delete(0);
80+
history.deleteFrom(0);
8181
expect(history.size()).toBe(0);
8282
expect(history.currentNode).toBe(history.root);
8383
expect(history.size()).toBe(0);
@@ -162,7 +162,7 @@ describe("using a tree-based history", () => {
162162
// eslint-disable-next-line jest/no-conditional-in-test
163163
if (typeof v === "number") {
164164
history.goTo(v - 1);
165-
history.delete(v);
165+
history.deleteFrom(v);
166166
} else {
167167
history.add(v);
168168
}
@@ -480,19 +480,19 @@ describe("using a tree-based history", () => {
480480
});
481481

482482
test("delete negative node ID ok", () => {
483-
history.delete(-1);
483+
history.deleteFrom(-1);
484484
expect(history.size()).toBe(1);
485485
expect(history.currentNode.undoable).toBe(undoable0);
486486
});
487487

488488
test("delete invalid ok", () => {
489-
history.delete(1);
489+
history.deleteFrom(1);
490490
expect(history.size()).toBe(1);
491491
expect(history.currentNode.undoable).toBe(undoable0);
492492
});
493493

494494
test("cannot delete the current branch", () => {
495-
history.delete(0);
495+
history.deleteFrom(0);
496496
expect(history.size()).toBe(1);
497497
expect(history.currentNode.undoable).toBe(undoable0);
498498
});
@@ -580,7 +580,7 @@ describe("using a tree-based history", () => {
580580

581581
test("delete one root is OK", () => {
582582
history.goTo(-1);
583-
history.delete(1);
583+
history.deleteFrom(1);
584584
expect(history.undoableNodes[0]?.undoable).toBe(undoable0);
585585
expect(history.undoableNodes[1]?.undoable).toBeUndefined();
586586
expect(history.size()).toBe(1);
@@ -763,7 +763,7 @@ describe("using a tree-based history", () => {
763763
test("get last redoable when moving to 4 and history and delete 4", () => {
764764
history.goTo(4);
765765
history.undo();
766-
history.delete(4);
766+
history.deleteFrom(4);
767767
expect(history.getLastRedo()).toBe(undoable3);
768768
expect(history.size()).toBe(4);
769769
});
@@ -810,7 +810,7 @@ describe("using a tree-based history", () => {
810810
});
811811

812812
test("delete 1", () => {
813-
history.delete(1);
813+
history.deleteFrom(1);
814814

815815
expect(history.size()).toBe(4);
816816
expect(history.currentNode.undoable).toBe(undoable4);
@@ -830,7 +830,7 @@ describe("using a tree-based history", () => {
830830

831831
test("delete 2", () => {
832832
history.goTo(0);
833-
history.delete(2);
833+
history.deleteFrom(2);
834834

835835
expect(history.size()).toBe(2);
836836
expect(history.currentNode.undoable).toBe(undoable0);
@@ -846,7 +846,7 @@ describe("using a tree-based history", () => {
846846

847847
test("delete 0", () => {
848848
history.goTo(1);
849-
history.delete(2);
849+
history.deleteFrom(2);
850850

851851
expect(history.size()).toBe(2);
852852
expect(history.currentNode.undoable).toBe(undoable1);
@@ -858,7 +858,7 @@ describe("using a tree-based history", () => {
858858
});
859859

860860
test("delete invalid 5", () => {
861-
history.delete(5);
861+
history.deleteFrom(5);
862862

863863
expect(history.size()).toBe(5);
864864
expect(history.currentNode.undoable).toBe(undoable4);

0 commit comments

Comments
 (0)