smartenv/dist/smartenv.objectstorage.js

47 lines
5.4 KiB
JavaScript
Raw Normal View History

2016-02-17 20:44:40 +00:00
/// <reference path="typings/main.d.ts" />
var plugins = require("./smartenv.plugins");
exports.obs = {
add: function (paramNameArg, objectArg) {
if (paramNameArg === void 0) { paramNameArg = "undefined"; }
if (objectArg === void 0) { objectArg = "undefined"; }
if (paramNameArg == "undefined") {
2016-02-23 15:31:50 +00:00
console.log("paramName is undefined");
2016-02-17 20:44:40 +00:00
return;
}
if (objectArg == "undefined") {
2016-02-23 15:31:50 +00:00
console.log("objectArg is undefined");
2016-02-17 20:44:40 +00:00
}
if (typeof exports.obsItems[paramNameArg] === "undefined") {
exports.obsItems[paramNameArg] = objectArg;
}
else {
2016-02-23 15:31:50 +00:00
console.log("object is already present, so add operation has failed.");
2016-02-17 20:44:40 +00:00
}
return exports.obsItems[paramNameArg];
},
replace: function (paramNameArg, objectArg) {
exports.obsItems[paramNameArg] = objectArg;
},
merge: function (paramNameArg, objectArg) {
if (!(typeof exports.obsItems[paramNameArg] === "undefined")) {
exports.obsItems[paramNameArg] = plugins._.assign(exports.obsItems[paramNameArg], objectArg);
}
else {
2016-02-23 15:31:50 +00:00
console.log("object is not present, so there is nothing to merge");
2016-02-17 20:44:40 +00:00
}
},
get: function (keyName) {
return exports.obsItems[keyName];
},
getAll: function () {
return exports.obsItems;
},
addComplete: function (itemsArg) {
exports.obsItems = plugins._.assign(exports.obsItems, itemsArg);
return exports.obsItems;
}
};
exports.obsItems = {};
2016-02-23 15:31:50 +00:00
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZW52Lm9iamVjdHN0b3JhZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsMENBQTBDO0FBQzFDLElBQU8sT0FBTyxXQUFXLG9CQUFvQixDQUFDLENBQUM7QUFDcEMsV0FBRyxHQUFPO0lBQ2pCLEdBQUcsRUFBRSxVQUFTLFl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