ngx-resource-gearheart
Version:
Angular2 resource module with simple decorators. Customized by Gearheart.
29 lines (28 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StorageAction = {
LOAD: function (storage, resp) {
storage.resultData = resp.filter(function (item) { return !!item; });
storage.forceRefresh();
},
ADD: function (storage, resp) {
storage.resultData.push(resp);
storage.forceRefresh();
},
UPDATE: function (storage, resp) {
var primaryKey = resp.$primaryKey || 'id';
var idx = storage.resultData.findIndex(function (item) { return item[primaryKey] === resp[primaryKey]; });
if (idx > -1) {
storage.resultData[idx] = resp;
storage.forceRefresh();
}
},
REMOVE: function (storage, resp) {
var primaryKey = resp.$primaryKey || 'id';
var idx = storage.resultData.findIndex(function (item) { return item[primaryKey] === resp[primaryKey]; });
if (idx > -1) {
storage.resultData.splice(idx, 1);
storage.forceRefresh();
}
},
};