smartenv/ts/smartenv.objectstorage.ts

45 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2016-11-21 10:58:37 +00:00
import plugins = require('./smartenv.plugins')
export let obsItems: any = {}
/**
* Objectstorage allows easy sharing of objects within node
*/
export let obs: any = {
add: function (paramNameArg = 'undefined', objectArg = 'undefined') {
if (paramNameArg === 'undefined') {
console.log('paramName is undefined')
return
2015-11-30 18:58:35 +00:00
}
if (objectArg === 'undefined') {
console.log('objectArg is undefined')
}
if (typeof obsItems[ paramNameArg ] === 'undefined') {
obsItems[ paramNameArg ] = objectArg
} else {
console.log('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.lodash.assign(obsItems[ paramNameArg ], objectArg)
} else {
console.log('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.lodash.assign(obsItems, itemsArg)
return obsItems
}
2016-11-21 10:58:37 +00:00
}