UNPKG

react-simple-modal-controller

Version:
29 lines (28 loc) 888 B
import { dispatchModal } from "./store"; var getRandomId = function () { return Math.random().toString(36).slice(2); }; var openAsync = function (Component, props) { var id = getRandomId(); return new Promise(function (resolve) { dispatchModal({ type: "OPEN_ASYNC", id: id, Component: Component, props: props, resolver: function (value) { resolve(value); modal.close(); }, }); }); }; var open = function (Component, props) { var id = getRandomId(); dispatchModal({ type: "OPEN", id: id, Component: Component, props: props }); }; var close = function () { dispatchModal({ type: "CLOSE" }); }; var clear = function () { dispatchModal({ type: "CLEAR" }); }; export var modal = { openAsync: openAsync, open: open, close: close, clear: clear };