UNPKG

2.9 kBJavaScriptView Raw
1import "core-js/modules/es.array.concat.js";
2import "core-js/modules/es.array.filter.js";
3import "core-js/modules/es.object.to-string.js";
4import "core-js/modules/es.array.find.js";
5import "core-js/modules/es.symbol.js";
6import "core-js/modules/es.symbol.description.js";
7import "core-js/modules/es.symbol.iterator.js";
8import "core-js/modules/es.array.iterator.js";
9import "core-js/modules/es.string.iterator.js";
10import "core-js/modules/web.dom-collections.iterator.js";
11import "core-js/modules/es.array.from.js";
12import "core-js/modules/es.array.slice.js";
13import "core-js/modules/es.function.name.js";
14import "core-js/modules/es.regexp.exec.js";
15
16function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
17
18function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
20function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
21
22function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
23
24function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
25
26function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
27
28export var init = function init(_ref) {
29 var store = _ref.store;
30 var api = {
31 addNotification: function addNotification(notification) {
32 // Get rid of it if already exists
33 api.clearNotification(notification.id);
34
35 var _store$getState = store.getState(),
36 notifications = _store$getState.notifications;
37
38 store.setState({
39 notifications: [].concat(_toConsumableArray(notifications), [notification])
40 });
41 },
42 clearNotification: function clearNotification(id) {
43 var _store$getState2 = store.getState(),
44 notifications = _store$getState2.notifications;
45
46 store.setState({
47 notifications: notifications.filter(function (n) {
48 return n.id !== id;
49 })
50 });
51 var notification = notifications.find(function (n) {
52 return n.id === id;
53 });
54
55 if (notification && notification.onClear) {
56 notification.onClear();
57 }
58 }
59 };
60 var state = {
61 notifications: []
62 };
63 return {
64 api: api,
65 state: state
66 };
67};
\No newline at end of file