lml-main
Version:
This is now a mono repository published into many standalone packages.
39 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var Actions = require("../actions");
exports.initialLocationsState = {
byId: {},
lastLocationsUpdate: null,
};
exports.locationApiReducer = function (state, action) {
if (state === void 0) { state = exports.initialLocationsState; }
switch (action.type) {
case Actions.SET_LOCATION_BY_OBJECT_ID: {
return setLocationByObjectId(state, action);
}
case Actions.SET_LOCATION_BY_OBJECT_ID_BATCH: {
return setLocationByObjectIdBatch(state, action);
}
default: {
return state;
}
}
};
var setLocationByObjectId = function (state, action) {
return (tslib_1.__assign({}, state, { byId: (_a = {},
_a[action.location.objectId] = action.location,
_a) }));
var _a;
};
var setLocationByObjectIdBatch = function (state, action) { return (tslib_1.__assign({}, state, { byId: tslib_1.__assign({}, state.byId, mkLocationMap(action.locations)),
// this is only set for batch calls which means
// its not updated by push events
lastLocationsUpdate: Date.now() })); };
var mkLocationMap = function (locations) {
return locations.reduce(function (acc, curr) {
acc[curr.objectId] = curr;
return acc;
}, {});
};
//# sourceMappingURL=data.js.map