Skip to content

Commit

Permalink
fix(alerts): fix regression causing alerts not to show
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyzerner committed Jun 25, 2023
1 parent 7342b88 commit da0b283
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/alerts/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type AlertOptions = {
export default class AlertsElement extends HTMLElement {
public static duration: number = 10000;

private added: Set<HTMLElement> = new Set();
private timeouts: WeakMap<HTMLElement, number> = new Map();
private index: number = 0;

Expand All @@ -18,7 +19,8 @@ export default class AlertsElement extends HTMLElement {
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
mutation.addedNodes.forEach((node) => {
if (node instanceof HTMLElement) this.show(node);
if (node instanceof HTMLElement && !this.added.has(node))
this.show(node);
});
});
});
Expand Down Expand Up @@ -64,6 +66,8 @@ export default class AlertsElement extends HTMLElement {
hello(el);
}

this.added.add(el);

const duration = Number(
options.duration !== undefined
? options.duration
Expand Down Expand Up @@ -95,15 +99,15 @@ export default class AlertsElement extends HTMLElement {
if (typeof elOrKey === 'string') {
this.querySelectorAll<HTMLElement>(
`[data-key="${elOrKey}"]`
).forEach((el) => {
this.dismiss(el);
});
).forEach((el) => this.dismiss(el));
return;
}

move(this.children, () => {
goodbye(elOrKey).then(() => this.removeChild(elOrKey));
});
this.added.delete(elOrKey);

move(this.children, () =>
goodbye(elOrKey).then(() => elOrKey.remove())
);

this.clearTimeout(elOrKey);
}
Expand Down

0 comments on commit da0b283

Please sign in to comment.