lml-main
Version:
This is now a mono repository published into many standalone packages.
41 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const actions_1 = require("../../couriers/actions");
exports.initialCourierFlagsState = {
active: null,
expanded: [],
};
exports.couriersFlagsReducer = (state = exports.initialCourierFlagsState, action) => {
switch (action.type) {
case actions_1.SET_ACTIVE_COURIER: {
return setActiveCourier(state, action);
}
case actions_1.UNSET_ACTIVE_COURIER: {
return unsetActiveCourier(state, action);
}
case actions_1.SET_EXPANDED_COURIER: {
return setExpandedCourier(state, action);
}
case actions_1.UNSET_EXPANDED_COURIER: {
return unsetExpandedCourier(state, action);
}
default: {
return state;
}
}
};
const setActiveCourier = (state, action) => (Object.assign({}, state, { active: action.refId }));
const unsetActiveCourier = (state, action) => {
// check to make sure we are unsetting the right courier
if (state.active !== action.refId) {
return state;
}
return (Object.assign({}, state, { active: null }));
};
const setExpandedCourier = (state, action) => (Object.assign({}, state, { expanded: lodash_1.union(state.expanded, [action.refId]) }));
const unsetExpandedCourier = (state, action) => {
console.log('UNSET EXPANDED COURIER', action, lodash_1.remove(state.expanded, action.refId));
return (Object.assign({}, state, { expanded: state.expanded.filter(i => i !== action.refId) }));
};
//# sourceMappingURL=flags.js.map