Skip to content

Commit 4a4ef55

Browse files
committed
fix(artist): clear unused timers
1 parent bab5359 commit 4a4ef55

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/misc/artist-ui/src/elements/spinner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ export const spinner = (_: any, ctx: any) => {
1212
interval,
1313
);
1414
ctx.disposer(() => {});
15-
return ` ${ctx.store.spinner || "..."} `;
15+
return ` ${ctx.store.spinner || frames[0]} `;
1616
};

packages/misc/artist-ui/src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class ArtistClass {
1717
private chalk = {};
1818
private disposers = [];
1919
private timers = {};
20+
private invokedTimers = [];
2021

2122
constructor(chalk = {}) {
2223
this.registerElements(uiElements);
@@ -61,6 +62,9 @@ class ArtistClass {
6162
handlebars.registerHelper("eq", function (arg1, arg2, options) {
6263
return arg1 === arg2 ? options.fn(this) : options.inverse(this);
6364
});
65+
handlebars.registerHelper("neq", function (arg1, arg2, options) {
66+
return arg1 !== arg2 ? options.fn(this) : options.inverse(this);
67+
});
6468
handlebars.registerHelper("list", (context, options) => {
6569
let ret = "";
6670

@@ -87,6 +91,7 @@ class ArtistClass {
8791
}
8892

8993
registerAndInvokeTimer(id, name, func, ms) {
94+
this.invokedTimers.push(id);
9095
if (this.timers[id]?.[name]) {
9196
return;
9297
}
@@ -108,6 +113,14 @@ class ArtistClass {
108113
});
109114
}
110115

116+
clearUnusedTimers() {
117+
Object.keys(this.timers).forEach((t) => {
118+
if (!this.invokedTimers.includes(t)) {
119+
clearInterval(this.timers[t]["intervalId"]);
120+
}
121+
});
122+
}
123+
111124
clearTimers() {
112125
Object.keys(this.timers).forEach((key: any) => {
113126
clearInterval(this.timers[key].intervalId);
@@ -185,6 +198,8 @@ class ArtistClass {
185198
}
186199

187200
render(tplStr: string) {
201+
this.clearUnusedTimers();
202+
this.invokedTimers = [];
188203
const minifiedStr = this.minifyTpl(tplStr);
189204
const compiledStr = this.compileTpl(minifiedStr);
190205
const elements = this.parseTpl(compiledStr);

0 commit comments

Comments
 (0)