Skip to content

Commit 87abcd2

Browse files
committed
refactor: - Manually inline findClosestParentTask() in ListItem.ts
1 parent 6081143 commit 87abcd2

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed

src/Task/ListItem.ts

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,22 @@ export class ListItem {
4747
return this.parent === null;
4848
}
4949

50+
/**
51+
* Find to find the closest parent that is a {@link Task}
52+
*/
5053
public findClosestParentTask(): Task | null {
51-
return findClosestParentTask(this);
54+
let closestParentTask = this.parent;
55+
56+
while (closestParentTask !== null) {
57+
// Lazy load the Task class to avoid circular dependencies
58+
const { Task } = require('./Task');
59+
if (closestParentTask instanceof Task) {
60+
return closestParentTask as Task;
61+
}
62+
closestParentTask = closestParentTask.parent;
63+
}
64+
65+
return null;
5266
}
5367

5468
get isTask() {
@@ -97,27 +111,3 @@ export class ListItem {
97111
return list1.every((item, index) => item.identicalTo(list2[index]));
98112
}
99113
}
100-
101-
/**
102-
* We want this function to be a method of ListItem but that causes a circular dependency
103-
* which makes the plugin fail to load in Obsidian.
104-
*
105-
* Note: the tests are in ListItem.test.ts
106-
*
107-
* @param listItem
108-
*/
109-
export function findClosestParentTask(listItem: ListItem): Task | null {
110-
// Try to find the closest parent that is a task
111-
let closestParentTask = listItem.parent;
112-
113-
while (closestParentTask !== null) {
114-
// Lazy load the Task class to avoid circular dependencies
115-
const { Task } = require('./Task');
116-
if (closestParentTask instanceof Task) {
117-
return closestParentTask as Task;
118-
}
119-
closestParentTask = closestParentTask.parent;
120-
}
121-
122-
return null;
123-
}

0 commit comments

Comments
 (0)