UNPKG

@nteract/mythic-notifications

Version:

A notification system based on blueprintjs toasters and the myths redux framework

31 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.sendNotification = void 0; const rxjs_1 = require("rxjs"); const package_1 = require("../package"); const prefixSlash = /.*\//; const camelCase = /([a-z])([A-Z])/g; const underscores = /_/g; const titleFromAction = (action) => { const text = action.type .replace(prefixSlash, "") .replace(camelCase, (...x) => `${x[1]} ${x[2]}`) .replace(underscores, " "); return (text.charAt(0).toUpperCase() + text.substr(1).toLowerCase()); }; const messageFromAction = (action) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j; return (_g = (_d = (_c = (_b = (_a = action) === null || _a === void 0 ? void 0 : _a.payload) === null || _b === void 0 ? void 0 : _b.error) === null || _c === void 0 ? void 0 : _c.message) !== null && _d !== void 0 ? _d : (_f = (_e = action) === null || _e === void 0 ? void 0 : _e.payload) === null || _f === void 0 ? void 0 : _f.message) !== null && _g !== void 0 ? _g : JSON.stringify((_j = (_h = action) === null || _h === void 0 ? void 0 : _h.payload) !== null && _j !== void 0 ? _j : action, null, 2); }; exports.sendNotification = package_1.notifications.createMyth("sendNotification")({ reduce: (state, action) => state.current.addNotification(action.payload), andAlso: [ { when: action => { var _a; return (_a = action.error) !== null && _a !== void 0 ? _a : false; }, dispatch: (action, _, sendNotificationMyth) => rxjs_1.of(sendNotificationMyth.create({ title: titleFromAction(action), message: messageFromAction(action), level: "error", })), }, ], }); //# sourceMappingURL=send-notification.js.map