mirror of
https://github.com/calfmoon/node-factor.git
synced 2026-07-22 05:42:24 +00:00
refactor(calc): use setTimeout instead of setInterval to loop
this was done as per suggestion of https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval , this makes it so that even if the task insides takes longer the tasks won't stack
This commit is contained in:
parent
04d5324e15
commit
bdf1a746b2
1 changed files with 12 additions and 11 deletions
23
src/main.ts
23
src/main.ts
|
|
@ -24,28 +24,29 @@ export default class NodeFactor extends Plugin {
|
|||
const start = performance.now();
|
||||
|
||||
const treeOptimizeMap: Map<string, number> = new Map();
|
||||
|
||||
nodes.forEach((node) => {
|
||||
const weight = this.calcNodeWeight(node, treeOptimizeMap);
|
||||
node.weight = weight;
|
||||
});
|
||||
|
||||
// setInterval(() => {
|
||||
// const treeOptimizeMap: Map<string, number> = new Map();
|
||||
// nodes.forEach((node) => {
|
||||
// const weight = this.calcNodeWeight(
|
||||
// node,
|
||||
// treeOptimizeMap,
|
||||
// );
|
||||
// node.weight = weight;
|
||||
// });
|
||||
// }, 10);
|
||||
// this.calcLoop(nodes);
|
||||
|
||||
console.log(performance.now() - start);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
private calcLoop(nodes: ObsidianNode[]) {
|
||||
setTimeout(() => {
|
||||
const treeOptimizeMap: Map<string, number> = new Map();
|
||||
nodes.forEach((node) => {
|
||||
const weight = this.calcNodeWeight(node, treeOptimizeMap);
|
||||
node.weight = weight;
|
||||
});
|
||||
this.calcLoop(nodes);
|
||||
}, 10);
|
||||
}
|
||||
|
||||
private calcNodeWeight(
|
||||
node: ObsidianNode,
|
||||
treeOptimizeMap: Map<string, number>,
|
||||
|
|
|
|||
Loading…
Reference in a new issue