wix-style-react
Version:
wix-style-react
33 lines • 995 B
JavaScript
import { eventManager } from './eventManager';
let container;
let queue = [];
eventManager
.on(2 /* Event.DidMount */, (containerInstance) => {
if (container) {
return;
}
container = containerInstance;
queue.forEach(item => {
eventManager.emit(0 /* Event.Show */, item.content, item.options);
});
queue = [];
})
.on(3 /* Event.WillUnmount */, () => {
container = undefined;
eventManager.off(0 /* Event.Show */).off(1 /* Event.Clear */);
});
const generateToastId = () => Math.random().toString(36).substring(2, 9);
const dispatchToast = (content, options) => {
container
? eventManager.emit(0 /* Event.Show */, content, options)
: queue.push({ content, options });
};
const mergeOptions = (options) => ({
...options,
toastId: generateToastId(),
});
const showToast = (content, options) => {
return dispatchToast(content, mergeOptions(options));
};
export { showToast };
//# sourceMappingURL=showToast.js.map