UNPKG

react-toastify-redux

Version:
35 lines (26 loc) 1.54 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _handlers; var _types = require('./types'); var types = _interopRequireWildcard(_types); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var initialState = []; var handlers = (_handlers = {}, _defineProperty(_handlers, types.TOAST_MESSAGE, function (toasts, action) { return toasts.concat(action.payload); }), _defineProperty(_handlers, types.TOAST_DISMISS, function (toasts, action) { return 'id' in action.payload ? toasts.filter(function (toast) { return toast.id !== action.payload.id; }) : []; }), _defineProperty(_handlers, types.TOAST_UPDATE, function (toasts, action) { return toasts.map(function (toast) { return toast.id === action.payload.id ? Object.assign({}, toast, action.payload.options) : toast; }); }), _handlers); exports.default = function () { var toasts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; var action = arguments[1]; return action.type in handlers ? handlers[action.type](toasts, action) : toasts; };