UNPKG

cosmo-ui

Version:
46 lines 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var ModalActions = require("../actions/modal"); var initialModalState = { modalType: '', modalProps: {}, modalHistory: [], }; exports.modalReducer = function (state, action) { if (state === void 0) { state = initialModalState; } switch (action.type) { case ModalActions.SHOW_MODAL: return showModal(state, action); case ModalActions.HIDE_MODAL: return hideModal(state, action); case ModalActions.UPDATE_MODAL_PROPS: return updateModal(state, action); default: return state; } }; var showModal = function (state, action) { if (state === void 0) { state = initialModalState; } var modalHistory = state.modalHistory.slice(0); if (state.modalType !== '') { modalHistory.push({ modalType: state.modalType, modalProps: state.modalProps }); } return tslib_1.__assign({}, state, { modalType: action.modalType, modalProps: action.modalProps, modalHistory: modalHistory }); }; var hideModal = function (state, action) { if (state === void 0) { state = initialModalState; } var modalHistory = state.modalHistory.slice(0); var oldState = (modalHistory.length > 0) ? modalHistory.pop() : null; if (oldState) { return tslib_1.__assign({}, state, { modalType: oldState.modalType, modalProps: oldState.modalProps, modalHistory: modalHistory }); } else { return initialModalState; } }; var updateModal = function (state, action) { if (state === void 0) { state = initialModalState; } return (tslib_1.__assign({}, state, { modalProps: action.modalProps })); }; //# sourceMappingURL=modal.js.map