Skip to content

Commit a2b24ad

Browse files
committed
Rename vars
1 parent 2242d4c commit a2b24ad

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/helpers/TreeModelHelper.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ describe('TreeModelHelper', () => {
88
let testTasks: TasksByProject | undefined;
99
beforeEach(() => {
1010
const factory = new TaskFactory();
11+
/* Structure:
12+
-task1
13+
--task1-1
14+
---task-1-1-1
15+
-task2
16+
--task21
17+
--task22
18+
*/
1119
const task111: Partial<IJsonTaskModel> = {
1220
key: '111',
1321
title: 'task1-1-1',
@@ -67,6 +75,7 @@ describe('TreeModelHelper', () => {
6775
'111',
6876
]);
6977
});
78+
7079
test('getPathToNode #2', () => {
7180
if (!testTasks) {
7281
throw new Error();

src/helpers/TreeModelHelper.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ const TreeModelHelper = {
2020
copyItemsToTree(
2121
sourceTree: TaskModel[],
2222
destTree: TaskInMyDay[],
23-
keysToTask: string[]
23+
keysToNode: string[]
2424
) {
2525
let keyIdx = 0;
2626
let sourceChildren = sourceTree;
2727
let destChildren = destTree;
2828

29-
if (keysToTask.length === 1) {
30-
const source = sourceChildren.find((node) => node.key === keysToTask[0]);
29+
if (keysToNode.length === 1) {
30+
const source = sourceChildren.find((node) => node.key === keysToNode[0]);
3131
if (source) {
3232
destChildren.push(TaskFactory.createTaskModelProxy(source));
3333
}
@@ -36,62 +36,64 @@ const TreeModelHelper = {
3636

3737
do {
3838
const nextSourceNode = sourceChildren.find(
39-
(task) => task.key === keysToTask[keyIdx]
39+
(task) => task.key === keysToNode[keyIdx]
4040
);
4141
if (!nextSourceNode) {
4242
return false;
4343
}
4444

4545
const nextDestNode = destChildren.find(
46-
(task) => task.key === keysToTask[keyIdx]
46+
(task) => task.key === keysToNode[keyIdx]
4747
);
4848

4949
if (nextDestNode) {
50+
// We already have a copy of node, go on
5051
keyIdx++;
5152
sourceChildren = nextSourceNode.children;
5253
destChildren = nextDestNode.children;
5354
} else {
54-
const restKeysToTask = keysToTask.slice(keyIdx);
55+
// Make a copy from this node
56+
const restKeysToNode = keysToNode.slice(keyIdx);
5557
return TreeModelHelper.copySubItemsToTree(
5658
sourceChildren,
5759
destChildren,
58-
restKeysToTask
60+
restKeysToNode
5961
);
6062
}
61-
} while (keyIdx < keysToTask.length);
63+
} while (keyIdx < keysToNode.length);
6264

6365
return true;
6466
},
6567

6668
copySubItemsToTree(
6769
sourceTree: TaskModel[],
6870
destTree: TaskInMyDay[],
69-
keysToTask: string[]
71+
keysToNode: string[]
7072
) {
7173
if (!sourceTree) {
7274
return false;
7375
}
7476

7577
let keyIdx = 0;
7678
let destChildren = destTree;
77-
let sourceNode = sourceTree.find((node) => node.key === keysToTask[keyIdx]);
79+
let sourceNode = sourceTree.find((node) => node.key === keysToNode[keyIdx]);
7880

7981
if (!sourceNode) {
8082
return false;
8183
}
8284

8385
while (true) {
84-
const copy = TaskFactory.createTaskModelProxy(sourceNode);
85-
destChildren.push(copy);
86+
const copyNode = TaskFactory.createTaskModelProxy(sourceNode);
87+
destChildren.push(copyNode);
8688

8789
keyIdx++;
88-
if (keyIdx === keysToTask.length) {
90+
if (keyIdx === keysToNode.length) {
8991
return true;
9092
}
9193

92-
destChildren = copy.children;
94+
destChildren = copyNode.children;
9395
sourceNode = sourceNode.children.find(
94-
(node) => node.key === keysToTask[keyIdx]
96+
(node) => node.key === keysToNode[keyIdx]
9597
);
9698
if (!sourceNode) {
9799
return false;

0 commit comments

Comments
 (0)