smartenv/dist/smartenv.objectstorage.js

48 lines
5.4 KiB
JavaScript
Raw Normal View History

2016-04-04 16:24:22 +00:00
"use strict";
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-05-01 23:29:42 +00:00
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNtYXJ0ZW52Lm9iamVjdHN0b3JhZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLDBDQUEwQztBQUMxQyxJQUFPLE9BQU8sV0FBVyxvQkFBb0IsQ0FBQyxDQUFDO0FBQ3BDLFdBQUcs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