Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 93x 93x 4x 4x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x | import { Alert, IAlert } from '../../components';
import { IAlertsManager } from './interfaces';
export class AlertStack implements IAlertsManager {
protected queue: IAlert[] = [];
public visibleInstances: Alert[] = [];
public show(alert: IAlert): number {
this.queue.push(alert);
return this.display(alert);
}
private display(alert: IAlert) {
const lastAlert = this.visibleInstances.slice(-1)[0];
const lastId = lastAlert?.id || 0;
const id = lastId + 1;
const instance = new Alert({ ...alert, id });
this.visibleInstances.push(instance);
instance.show();
return id;
}
remove(index: number): void {
this.queue.splice(index, 1);
this.visibleInstances.splice(index, 1);
}
}
|