@hixme/modal
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.MrModalManager = exports.setView = exports.setData = exports.hasActiveModal = exports.getModalData = exports.getModal = exports.getCurrentView = exports.clearModal = exports.NAME = exports.MrModal = undefined; | ||
exports.MrModalManager = exports.setView = exports.setData = exports.removeFromViewList = exports.hasActiveModal = exports.getViewList = exports.getModalData = exports.getModal = exports.getCurrentView = exports.clearModal = exports.addToViewList = exports.NAME = exports.MrModal = undefined; | ||
@@ -17,2 +17,8 @@ var _modules = require('./modules'); | ||
}); | ||
Object.defineProperty(exports, 'addToViewList', { | ||
enumerable: true, | ||
get: function get() { | ||
return _modules.addToViewList; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'clearModal', { | ||
@@ -42,2 +48,8 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, 'getViewList', { | ||
enumerable: true, | ||
get: function get() { | ||
return _modules.getViewList; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'hasActiveModal', { | ||
@@ -49,2 +61,8 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, 'removeFromViewList', { | ||
enumerable: true, | ||
get: function get() { | ||
return _modules.removeFromViewList; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'setData', { | ||
@@ -51,0 +69,0 @@ enumerable: true, |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.getModalData = exports.hasActiveModal = exports.getCurrentView = exports.getModal = exports.setData = exports.clearModal = exports.setView = exports.NAME = undefined; | ||
exports.getModalData = exports.hasActiveModal = exports.getViewList = exports.getCurrentView = exports.getModal = exports.removeFromViewList = exports.addToViewList = exports.setData = exports.clearModal = exports.setView = exports.NAME = undefined; | ||
@@ -13,2 +13,10 @@ var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _assign = require('babel-runtime/core-js/object/assign'); | ||
@@ -33,4 +41,6 @@ | ||
var SET_VIEW = 'SET_VIEW'; | ||
var ADD_TO_VIEW_LIST = 'ADD_TO_VIEW_LIST'; | ||
var REMOVE_FROM_VIEW_LIST = 'REMOVE_FROM_VIEW_LIST'; | ||
(0, _reduxUtils.namespaceActions)(NAME)([CLEAR_MODAL, SET_DATA, SET_VIEW]); | ||
(0, _reduxUtils.namespaceActions)(NAME)([CLEAR_MODAL, SET_DATA, SET_VIEW, ADD_TO_VIEW_LIST, REMOVE_FROM_VIEW_LIST]); | ||
@@ -63,2 +73,16 @@ var setView = exports.setView = function setView(view) { | ||
var addToViewList = exports.addToViewList = function addToViewList(payload) { | ||
return { | ||
type: ADD_TO_VIEW_LIST, | ||
payload: payload | ||
}; | ||
}; | ||
var removeFromViewList = exports.removeFromViewList = function removeFromViewList(payload) { | ||
return { | ||
type: REMOVE_FROM_VIEW_LIST, | ||
payload: payload | ||
}; | ||
}; | ||
// Selectors | ||
@@ -77,2 +101,8 @@ var getModal = exports.getModal = (0, _reselect.createSelector)(function (state) { | ||
var getViewList = exports.getViewList = (0, _reselect.createSelector)(function (state) { | ||
return state[NAME]; | ||
}, function (modal) { | ||
return modal.viewList; | ||
}); | ||
var hasActiveModal = exports.hasActiveModal = (0, _reselect.createSelector)(function (state) { | ||
@@ -92,2 +122,3 @@ return state[NAME]; | ||
var initialState = { | ||
viewList: {}, | ||
view: null, | ||
@@ -110,3 +141,17 @@ data: {} | ||
}); | ||
}), (0, _defineProperty3.default)(_createReducer, ADD_TO_VIEW_LIST, function (state, payload) { | ||
return (0, _extends3.default)({}, state, { | ||
viewList: (0, _extends3.default)({}, state.viewList, payload) | ||
}); | ||
}), (0, _defineProperty3.default)(_createReducer, REMOVE_FROM_VIEW_LIST, function (state, payload) { | ||
var newViewList = (0, _keys2.default)(payload).reduce(function (acc, currItem) { | ||
var accCopy = (0, _extends3.default)({}, acc); | ||
delete accCopy[currItem]; | ||
return accCopy; | ||
}, (0, _extends3.default)({}, state.viewList)); | ||
return (0, _extends3.default)({}, state, { | ||
viewList: (0, _extends3.default)({}, newViewList) | ||
}); | ||
}), _createReducer)); | ||
//# sourceMappingURL=index.js.map |
@@ -56,3 +56,5 @@ 'use strict'; | ||
value: function componentDidMount() { | ||
var appElementId = this.props.appElementId; | ||
var _props = this.props, | ||
appElementId = _props.appElementId, | ||
modals = _props.modals; | ||
@@ -62,2 +64,4 @@ | ||
_reactModal2.default.setAppElement(MODAL_HIDE_NODE); | ||
this.props.dispatch((0, _modules.addToViewList)(modals)); | ||
} | ||
@@ -67,10 +71,10 @@ }, { | ||
value: function render() { | ||
var _props = this.props, | ||
currentModal = _props.currentModal, | ||
modals = _props.modals; | ||
var _props2 = this.props, | ||
currentModal = _props2.currentModal, | ||
viewList = _props2.viewList; | ||
var hasModal = Object.prototype.hasOwnProperty.call(modals, currentModal.view); | ||
var hasModal = Object.prototype.hasOwnProperty.call(viewList, currentModal.view); | ||
if (hasModal) { | ||
var MyModalComponent = modals[currentModal.view]; | ||
var MyModalComponent = viewList[currentModal.view]; | ||
return _react2.default.createElement(MyModalComponent, currentModal); | ||
@@ -87,3 +91,5 @@ } | ||
currentModal: _propTypes2.default.object, | ||
modals: _propTypes2.default.object | ||
viewList: _propTypes2.default.object, | ||
modals: _propTypes2.default.object, | ||
dispatch: _propTypes2.default.func.isRequired | ||
}; | ||
@@ -93,2 +99,3 @@ | ||
currentModal: {}, | ||
viewList: {}, | ||
modals: {} | ||
@@ -100,5 +107,8 @@ }; | ||
exports.default = (0, _reactRedux.connect)(function (state) { | ||
return { currentModal: (0, _modules.getModal)(state) }; | ||
return { | ||
currentModal: (0, _modules.getModal)(state), | ||
viewList: (0, _modules.getViewList)(state) | ||
}; | ||
})(MrModalManager); | ||
module.exports = exports['default']; | ||
//# sourceMappingURL=MrModalManager.js.map |
{ | ||
"name": "@hixme/modal", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "Hixme Modal", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -7,2 +7,3 @@ import MrModalContainer from './components/MrModalContainer' | ||
NAME, | ||
addToViewList, | ||
clearModal, | ||
@@ -12,3 +13,5 @@ getCurrentView, | ||
getModalData, | ||
getViewList, | ||
hasActiveModal, | ||
removeFromViewList, | ||
setData, | ||
@@ -15,0 +18,0 @@ setView, |
@@ -11,2 +11,4 @@ import { createReducer, namespaceActions } from '@hixme/redux-utils' | ||
const SET_VIEW = 'SET_VIEW' | ||
const ADD_TO_VIEW_LIST = 'ADD_TO_VIEW_LIST' | ||
const REMOVE_FROM_VIEW_LIST = 'REMOVE_FROM_VIEW_LIST' | ||
@@ -17,2 +19,4 @@ namespaceActions(NAME)([ | ||
SET_VIEW, | ||
ADD_TO_VIEW_LIST, | ||
REMOVE_FROM_VIEW_LIST, | ||
]) | ||
@@ -40,2 +44,12 @@ | ||
export const addToViewList = payload => ({ | ||
type: ADD_TO_VIEW_LIST, | ||
payload, | ||
}) | ||
export const removeFromViewList = payload => ({ | ||
type: REMOVE_FROM_VIEW_LIST, | ||
payload, | ||
}) | ||
// Selectors | ||
@@ -52,2 +66,7 @@ export const getModal = createSelector( | ||
export const getViewList = createSelector( | ||
state => state[NAME], | ||
modal => modal.viewList, | ||
) | ||
export const hasActiveModal = createSelector( | ||
@@ -65,2 +84,3 @@ state => state[NAME], | ||
const initialState = { | ||
viewList: {}, | ||
view: null, | ||
@@ -81,2 +101,21 @@ data: {}, | ||
}), | ||
[ADD_TO_VIEW_LIST]: (state, payload) => ({ | ||
...state, | ||
viewList: { | ||
...state.viewList, | ||
...payload, | ||
}, | ||
}), | ||
[REMOVE_FROM_VIEW_LIST]: (state, payload) => { | ||
const newViewList = Object.keys(payload).reduce((acc, currItem) => { | ||
const accCopy = { ...acc } | ||
delete accCopy[currItem] | ||
return accCopy | ||
}, { ...state.viewList }) | ||
return { | ||
...state, | ||
viewList: { ...newViewList }, | ||
} | ||
}, | ||
}) |
@@ -6,3 +6,3 @@ import React, { Component } from 'react' | ||
import { getModal } from './modules' | ||
import { addToViewList, getViewList, getModal } from './modules' | ||
@@ -13,2 +13,3 @@ class MrModalManager extends Component { | ||
appElementId, | ||
modals, | ||
} = this.props | ||
@@ -18,2 +19,4 @@ | ||
Modal.setAppElement(MODAL_HIDE_NODE) | ||
this.props.dispatch(addToViewList(modals)) | ||
} | ||
@@ -24,8 +27,8 @@ | ||
currentModal, | ||
modals, | ||
viewList, | ||
} = this.props | ||
const hasModal = Object.prototype.hasOwnProperty.call(modals, currentModal.view) | ||
const hasModal = Object.prototype.hasOwnProperty.call(viewList, currentModal.view) | ||
if (hasModal) { | ||
const MyModalComponent = modals[currentModal.view] | ||
const MyModalComponent = viewList[currentModal.view] | ||
return <MyModalComponent {...currentModal} /> | ||
@@ -40,3 +43,5 @@ } | ||
currentModal: PropTypes.object, | ||
viewList: PropTypes.object, | ||
modals: PropTypes.object, | ||
dispatch: PropTypes.func.isRequired, | ||
} | ||
@@ -46,2 +51,3 @@ | ||
currentModal: {}, | ||
viewList: {}, | ||
modals: {}, | ||
@@ -52,2 +58,7 @@ } | ||
export default connect(state => ({ currentModal: getModal(state) }))(MrModalManager) | ||
export default connect( | ||
state => ({ | ||
currentModal: getModal(state), | ||
viewList: getViewList(state), | ||
}), | ||
)(MrModalManager) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39376
649