insomnia/app/redux/modules/modals.js
2016-04-22 23:16:23 -07:00

39 lines
672 B
JavaScript

const MODAL_SHOW = 'modals/show';
const MODAL_HIDE = 'modals/hide';
const initialState = [];
// ~~~~~~~~ //
// REDUCERS //
// ~~~~~~~~ //
export default function (state = initialState, action) {
switch (action.type) {
case MODAL_SHOW:
let id = action.id;
let data = action.data;
return [...state.filter(m => m.id !== action.id), {id, data}];
case MODAL_HIDE:
return state.filter(m => m.id !== action.id);
default:
return state
}
}
// ~~~~~~~ //
// ACTIONS //
// ~~~~~~~ //
export function hide (id) {
return {type: MODAL_HIDE, id}
}
export function show (id, data = {}) {
return {type: MODAL_SHOW, id, data};
}