added merge and replace operations for objectstorage
This commit is contained in:
parent
2df7cf1467
commit
a6839420f1
64
index.js
64
index.js
@ -71,30 +71,48 @@ var SmartenvEnvironment;
|
|||||||
var SmartenvObjectStorage;
|
var SmartenvObjectStorage;
|
||||||
(function (SmartenvObjectStorage) {
|
(function (SmartenvObjectStorage) {
|
||||||
function init() {
|
function init() {
|
||||||
var obs = {};
|
var obs = {
|
||||||
|
add: function (paramNameArg, objectArg) {
|
||||||
|
if (paramNameArg === void 0) { paramNameArg = "undefined"; }
|
||||||
|
if (objectArg === void 0) { objectArg = "undefined"; }
|
||||||
|
if (paramNameArg == "undefined") {
|
||||||
|
plugins.beautylog.error("paramName is undefined");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objectArg == "undefined") {
|
||||||
|
plugins.beautylog.error("objectArg is undefined");
|
||||||
|
}
|
||||||
|
if (typeof obsItems[paramNameArg] === "undefined") {
|
||||||
|
obsItems[paramNameArg] = objectArg;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
plugins.beautylog.error("object is already present, so add operation has failed.");
|
||||||
|
}
|
||||||
|
return obsItems[paramNameArg];
|
||||||
|
},
|
||||||
|
replace: function (paramNameArg, objectArg) {
|
||||||
|
obsItems[paramNameArg] = objectArg;
|
||||||
|
},
|
||||||
|
merge: function (paramNameArg, objectArg) {
|
||||||
|
if (!(typeof obsItems[paramNameArg] === "undefined")) {
|
||||||
|
obsItems[paramNameArg] = plugins._.assign(obsItems[paramNameArg], objectArg);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
plugins.beautylog.error("object is not present, so there is nothing to merge");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get: function (keyName) {
|
||||||
|
return obsItems[keyName];
|
||||||
|
},
|
||||||
|
getAll: function () {
|
||||||
|
return obsItems;
|
||||||
|
},
|
||||||
|
addComplete: function (itemsArg) {
|
||||||
|
obsItems = plugins._.assign(obsItems, itemsArg);
|
||||||
|
return obsItems;
|
||||||
|
}
|
||||||
|
};
|
||||||
var obsItems = {};
|
var obsItems = {};
|
||||||
obs.add = function (paramNameArg, objectArg) {
|
|
||||||
if (paramNameArg === void 0) { paramNameArg = "undefined"; }
|
|
||||||
if (objectArg === void 0) { objectArg = "undefined"; }
|
|
||||||
if (paramNameArg == "undefined") {
|
|
||||||
plugins.beautylog.error("paramName is undefined");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (objectArg == "undefined") {
|
|
||||||
plugins.beautylog.error("objectArg is undefined");
|
|
||||||
}
|
|
||||||
obsItems[paramNameArg] = objectArg;
|
|
||||||
};
|
|
||||||
obs.get = function (keyName) {
|
|
||||||
return obsItems[keyName];
|
|
||||||
};
|
|
||||||
obs.getAll = function () {
|
|
||||||
return obsItems;
|
|
||||||
};
|
|
||||||
obs.addComplete = function (itemsArg) {
|
|
||||||
obsItems = plugins._.assign(obsItems, itemsArg);
|
|
||||||
return obsItems;
|
|
||||||
};
|
|
||||||
return obs;
|
return obs;
|
||||||
}
|
}
|
||||||
SmartenvObjectStorage.init = init;
|
SmartenvObjectStorage.init = init;
|
||||||
|
17
test.js
17
test.js
@ -4,11 +4,18 @@ var beautylog = require("beautylog")("os");
|
|||||||
beautylog.info("Now testing the smartenv module");
|
beautylog.info("Now testing the smartenv module");
|
||||||
smartenv.printEnv();
|
smartenv.printEnv();
|
||||||
beautylog.info("Now testing the smartenv module");
|
beautylog.info("Now testing the smartenv module");
|
||||||
smartenv.obs.add("docit", { key1: "Peter" });
|
//test smartenv.obs.add
|
||||||
|
smartenv.obs.add("myTestObject", { key1: "Peter" });
|
||||||
|
smartenv.obs.add("myTestObject", { key1: "Klaus" }); //now trying to add a second
|
||||||
smartenv.printEnv();
|
smartenv.printEnv();
|
||||||
beautylog.log(smartenv.obs.get("docit").key1);
|
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Peter
|
||||||
beautylog.log(smartenv.obs.get("docit").key1);
|
//test smartenv.obs.replace
|
||||||
|
smartenv.obs.replace("myTestObject", { key1: "Klaus" });
|
||||||
|
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Klaus
|
||||||
|
//test smartenv.obs.merge
|
||||||
|
smartenv.obs.merge("myTestObject", { key2: "Peter" });
|
||||||
|
beautylog.log(smartenv.obs.get("myTestObject").key1 + smartenv.obs.get("myTestObject").key2); // this should be KlausPeter
|
||||||
var key2 = "hello";
|
var key2 = "hello";
|
||||||
smartenv.obs.get("docit").key2 = key2;
|
smartenv.obs.get("myTestObject").key2 = key2;
|
||||||
beautylog.log(smartenv.obs.get("docit").key2);
|
beautylog.log(smartenv.obs.get("myTestObject").key2);
|
||||||
beautylog.success("Success!");
|
beautylog.success("Success!");
|
||||||
|
@ -1,29 +1,44 @@
|
|||||||
/// <reference path="index.ts" />
|
/// <reference path="index.ts" />
|
||||||
module SmartenvObjectStorage {
|
module SmartenvObjectStorage {
|
||||||
export function init() {
|
export function init() {
|
||||||
var obs:any = {};
|
var obs:any = {
|
||||||
|
add: function(paramNameArg = "undefined",objectArg = "undefined") {
|
||||||
|
if (paramNameArg == "undefined"){
|
||||||
|
plugins.beautylog.error("paramName is undefined");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (objectArg == "undefined"){
|
||||||
|
plugins.beautylog.error("objectArg is undefined");
|
||||||
|
}
|
||||||
|
if (typeof obsItems[paramNameArg] === "undefined"){
|
||||||
|
obsItems[paramNameArg] = objectArg;
|
||||||
|
} else {
|
||||||
|
plugins.beautylog.error("object is already present, so add operation has failed.");
|
||||||
|
}
|
||||||
|
return obsItems[paramNameArg];
|
||||||
|
},
|
||||||
|
replace: function(paramNameArg,objectArg){
|
||||||
|
obsItems[paramNameArg] = objectArg;
|
||||||
|
},
|
||||||
|
merge: function(paramNameArg,objectArg){
|
||||||
|
if(!(typeof obsItems[paramNameArg] === "undefined")){
|
||||||
|
obsItems[paramNameArg] = plugins._.assign(obsItems[paramNameArg],objectArg);
|
||||||
|
} else {
|
||||||
|
plugins.beautylog.error("object is not present, so there is nothing to merge");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get: function(keyName) {
|
||||||
|
return obsItems[keyName];
|
||||||
|
},
|
||||||
|
getAll: function () {
|
||||||
|
return obsItems;
|
||||||
|
},
|
||||||
|
addComplete: function(itemsArg) {
|
||||||
|
obsItems = plugins._.assign(obsItems,itemsArg);
|
||||||
|
return obsItems;
|
||||||
|
}
|
||||||
|
};
|
||||||
var obsItems:any = {};
|
var obsItems:any = {};
|
||||||
obs.add = function(paramNameArg = "undefined",objectArg = "undefined") {
|
|
||||||
if (paramNameArg == "undefined"){
|
|
||||||
plugins.beautylog.error("paramName is undefined");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (objectArg == "undefined"){
|
|
||||||
plugins.beautylog.error("objectArg is undefined");
|
|
||||||
}
|
|
||||||
obsItems[paramNameArg] = objectArg;
|
|
||||||
};
|
|
||||||
obs.get = function(keyName) {
|
|
||||||
return obsItems[keyName];
|
|
||||||
};
|
|
||||||
obs.getAll = function () {
|
|
||||||
return obsItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
obs.addComplete = function(itemsArg) {
|
|
||||||
obsItems = plugins._.assign(obsItems,itemsArg);
|
|
||||||
return obsItems;
|
|
||||||
};
|
|
||||||
return obs;
|
return obs;
|
||||||
}
|
}
|
||||||
}
|
}
|
17
ts/test.js
17
ts/test.js
@ -4,12 +4,19 @@ var beautylog = require("beautylog")("os");
|
|||||||
beautylog.info("Now testing the smartenv module");
|
beautylog.info("Now testing the smartenv module");
|
||||||
smartenv.printEnv();
|
smartenv.printEnv();
|
||||||
beautylog.info("Now testing the smartenv module");
|
beautylog.info("Now testing the smartenv module");
|
||||||
smartenv.obs.add("docit", { key1: "Peter" });
|
//test smartenv.obs.add
|
||||||
|
smartenv.obs.add("myTestObject", { key1: "Peter" });
|
||||||
|
smartenv.obs.add("myTestObject", { key1: "Klaus" }); //now trying to add a second
|
||||||
smartenv.printEnv();
|
smartenv.printEnv();
|
||||||
beautylog.log(smartenv.obs.get("docit").key1);
|
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Peter
|
||||||
beautylog.log(smartenv.obs.get("docit").key1);
|
//test smartenv.obs.replace
|
||||||
|
smartenv.obs.replace("myTestObject", { key1: "Klaus" });
|
||||||
|
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Klaus
|
||||||
|
//test smartenv.obs.merge
|
||||||
|
smartenv.obs.merge("myTestObject", { key2: "Peter" });
|
||||||
|
beautylog.log(smartenv.obs.get("myTestObject").key1 + smartenv.obs.get("myTestObject").key2); // this should be KlausPeter
|
||||||
var key2 = "hello";
|
var key2 = "hello";
|
||||||
smartenv.obs.get("docit").key2 = key2;
|
smartenv.obs.get("myTestObject").key2 = key2;
|
||||||
beautylog.log(smartenv.obs.get("docit").key2);
|
beautylog.log(smartenv.obs.get("myTestObject").key2);
|
||||||
beautylog.success("Success!");
|
beautylog.success("Success!");
|
||||||
//# sourceMappingURL=test.js.map
|
//# sourceMappingURL=test.js.map
|
@ -1 +1 @@
|
|||||||
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,IAAI,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AACrC,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;AAC3C,SAAS,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAClD,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACpB,SAAS,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAClD,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,CAAC,CAAC;AACzC,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACpB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;AAC9C,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,C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cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,uBAAuB;AAE7E,yBAAyB;AACzB,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,cAAc,EAAC,EAAC,IAAI,EAAC,OAAO,EAAC,CAAC,CAAC;AAClD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,4BAA4B;AAE1H,IAAI,IAAI,GAAG,OAAO,CAAC;AACnB,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;AAC7C,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,CAAC;AAErD,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC"}
|
20
ts/test.ts
20
ts/test.ts
@ -4,13 +4,23 @@ var beautylog = require("beautylog")("os");
|
|||||||
beautylog.info("Now testing the smartenv module");
|
beautylog.info("Now testing the smartenv module");
|
||||||
smartenv.printEnv();
|
smartenv.printEnv();
|
||||||
beautylog.info("Now testing the smartenv module");
|
beautylog.info("Now testing the smartenv module");
|
||||||
smartenv.obs.add("docit",{key1:"Peter"});
|
|
||||||
|
//test smartenv.obs.add
|
||||||
|
smartenv.obs.add("myTestObject",{key1:"Peter"});
|
||||||
|
smartenv.obs.add("myTestObject",{key1:"Klaus"}); //now trying to add a second
|
||||||
smartenv.printEnv();
|
smartenv.printEnv();
|
||||||
beautylog.log(smartenv.obs.get("docit").key1);
|
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Peter
|
||||||
beautylog.log(smartenv.obs.get("docit").key1);
|
|
||||||
|
//test smartenv.obs.replace
|
||||||
|
smartenv.obs.replace("myTestObject",{key1:"Klaus"});
|
||||||
|
beautylog.log(smartenv.obs.get("myTestObject").key1); // this should be Klaus
|
||||||
|
|
||||||
|
//test smartenv.obs.merge
|
||||||
|
smartenv.obs.merge("myTestObject",{key2:"Peter"});
|
||||||
|
beautylog.log(smartenv.obs.get("myTestObject").key1 + smartenv.obs.get("myTestObject").key2); // this should be KlausPeter
|
||||||
|
|
||||||
var key2 = "hello";
|
var key2 = "hello";
|
||||||
smartenv.obs.get("docit").key2 = key2;
|
smartenv.obs.get("myTestObject").key2 = key2;
|
||||||
beautylog.log(smartenv.obs.get("docit").key2);
|
beautylog.log(smartenv.obs.get("myTestObject").key2);
|
||||||
|
|
||||||
beautylog.success("Success!");
|
beautylog.success("Success!");
|
Loading…
Reference in New Issue
Block a user