mirror of
https://github.com/Terncode/pixel.horse.git
synced 2026-09-25 06:05:52 +02:00
tslint changes
This commit is contained in:
@@ -2,43 +2,43 @@ import { Injectable, NgZone } from '@angular/core';
|
||||
import { removeItem } from '../../common/utils';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class IntervalUpdateService {
|
||||
private interval: any;
|
||||
private actions: (() => void)[] = [];
|
||||
constructor(private zone: NgZone) {
|
||||
}
|
||||
subscribe(action: () => void) {
|
||||
this.actions.push(action);
|
||||
private interval: any;
|
||||
private actions: (() => void)[] = [];
|
||||
constructor(private zone: NgZone) {
|
||||
}
|
||||
subscribe(action: () => void) {
|
||||
this.actions.push(action);
|
||||
|
||||
if (!this.interval) {
|
||||
this.zone.runOutsideAngular(() => {
|
||||
this.interval = setInterval(() => {
|
||||
this.actions.forEach(a => a());
|
||||
}, 1000 * 10);
|
||||
});
|
||||
}
|
||||
if (!this.interval) {
|
||||
this.zone.runOutsideAngular(() => {
|
||||
this.interval = setInterval(() => {
|
||||
this.actions.forEach(a => a());
|
||||
}, 1000 * 10);
|
||||
});
|
||||
}
|
||||
|
||||
return () => {
|
||||
removeItem(this.actions, action);
|
||||
return () => {
|
||||
removeItem(this.actions, action);
|
||||
|
||||
if (this.actions.length === 0) {
|
||||
clearInterval(this.interval);
|
||||
this.interval = undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
toggle(action: () => void) {
|
||||
let unsubscribe: (() => void) | undefined;
|
||||
if (this.actions.length === 0) {
|
||||
clearInterval(this.interval);
|
||||
this.interval = undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
toggle(action: () => void) {
|
||||
let unsubscribe: (() => void) | undefined;
|
||||
|
||||
return (on: boolean) => {
|
||||
if (on && !unsubscribe) {
|
||||
unsubscribe = this.subscribe(action);
|
||||
} else if (!on && unsubscribe) {
|
||||
unsubscribe();
|
||||
unsubscribe = undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
return (on: boolean) => {
|
||||
if (on && !unsubscribe) {
|
||||
unsubscribe = this.subscribe(action);
|
||||
} else if (!on && unsubscribe) {
|
||||
unsubscribe();
|
||||
unsubscribe = undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user