insomnia/app/ui/components/modals/index.js

33 lines
671 B
JavaScript
Raw Normal View History

const modals = {};
export function registerModal (instance) {
if (instance === null) {
// Modal was unmounted
return;
}
modals[instance.constructor.name] = instance;
}
export function showModal (modalCls, ...args) {
return _getModal(modalCls).show(...args);
}
export function toggleModal (modalCls, ...args) {
return _getModal(modalCls).toggle(...args);
}
export function hideModal (modalCls) {
return _getModal(modalCls).hide();
}
2017-03-29 02:21:49 +00:00
export function hideAllModals () {
for (const key of Object.keys(modals)) {
const modal = modals[key];
modal.hide && modal.hide();
}
}
function _getModal (modalCls) {
return modals[modalCls.name];
}