lml-main
Version:
This is now a mono repository published into many standalone packages.
56 lines • 2.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Actions = require("../actions");
var lodash_1 = require("lodash");
exports.initialCouriersState = {
byId: {},
callsigns: {},
lastStatusUpdate: null,
};
exports.courierDataReducer = function (state, action) {
if (state === void 0) { state = exports.initialCouriersState; }
switch (action.type) {
case Actions.SET_COURIER_BY_ID: {
return setCourierById(state, action);
}
case Actions.SET_COURIERS_BY_ID_BATCH: {
return setCouriersByIdBatch(state, action);
}
case Actions.SET_COURIER_LABEL: {
return setCourierLabel(state, action);
}
// obviously this shouldn't be here
// this is a shitty hack because the backend aren't giving us the callsigns yet
case Actions.SET_COURIER_CALLSIGNS: {
return setCourierCallsigns(state, action);
}
default: {
return state;
}
}
};
var setCourierById = function (state, action) {
return (tslib_1.__assign({}, state, { byId: tslib_1.__assign({}, state.byId, (_a = {}, _a[action.courier.refId] = action.courier, _a)), lastStatusUpdate: Date.now() }));
var _a;
};
var setCouriersByIdBatch = function (state, action) {
var updates = action.couriers
.reduce(function (acc, curr) {
acc[curr.refId] = curr;
return acc;
}, {});
return tslib_1.__assign({}, state, { byId: tslib_1.__assign({}, state.byId, updates), lastStatusUpdate: Date.now() });
};
var setCourierLabel = function (state, action) {
var courier = lodash_1.cloneDeep(state.byId[action.refId]);
courier.label.label = action.label;
return tslib_1.__assign({}, state, { byId: tslib_1.__assign({}, state.byId, (_a = {}, _a[action.refId] = courier, _a)) });
var _a;
};
// todo - remove this function along with callsigns hack
var setCourierCallsigns = function (state, action) {
var callsigns = action.callsigns;
return tslib_1.__assign({}, state, { callsigns: tslib_1.__assign({}, state.callsigns, callsigns) });
};
//# sourceMappingURL=data.js.map