Skip to content

Commit f2fbaae

Browse files
committed
feat: Specify close reason
Bump to 2.0 because the last thing was breaking
1 parent 7c2004b commit f2fbaae

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

simpletoast.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
console.log(`SimpleToast(v${localToast.versionString}): Publicized`);
1515
}
1616
})(this, () => {
17-
const version = buildVersion(1, 13, 0);
17+
const version = buildVersion(2, 0, 0);
1818
const style = {
1919
root: {
2020
display: 'flex',
@@ -121,7 +121,7 @@
121121
pending += 1;
122122
return;
123123
}
124-
toast.timedout();
124+
toast.close('timeout');
125125
});
126126
if (pending) {
127127
startTimeout();
@@ -164,31 +164,22 @@
164164
applyCSS(fel, css.footer);
165165
fel.innerHTML = footer;
166166
}
167-
168-
let closeType = 'unknown';
167+
169168
const safeToast = {};
170169
const toast = {
171170
setText: (newText) => {
172171
if (!newText || !toast.exists()) return;
173172
body.innerHTML = newText;
174173
},
175174
exists: () => toasts.has(id),
176-
close: () => {
175+
close: (closeType) => {
177176
if (!toast.exists()) return;
178177
root.removeChild(el);
179178
toasts.delete(id);
180179
if (typeof onClose === 'function') {
181-
onClose.call(safeToast, closeType, safeToast);
180+
onClose.call(safeToast, closeType || 'unknown', safeToast);
182181
}
183182
},
184-
timedout: () => {
185-
closeType = 'timeout';
186-
toast.close();
187-
},
188-
closed: () => {
189-
closeType = 'dismissed';
190-
toast.close();
191-
},
192183
};
193184
if (timeout) {
194185
toast.timeout = Date.now() + timeout;
@@ -229,7 +220,7 @@
229220
el.insertBefore(elb, fel);
230221
});
231222
}
232-
el.addEventListener('click', toast.closed);
223+
el.addEventListener('click', toast.close.bind(null, 'dismissed'));
233224

234225
root.appendChild(el);
235226
toasts.set(id, toast);

0 commit comments

Comments
 (0)