webu
Version:
IrChain JavaScript API, middleware to talk to a irchain node over RPC
47 lines (38 loc) • 1.31 kB
JavaScript
var formatters = require('./formatters');
var utils = require('./../utils/utils');
var Method = require('./method');
var Property = require('./property');
// TODO: refactor, so the input params are not altered.
// it's necessary to make same 'extension' work with multiple providers
var extend = function(webu) {
/* jshint maxcomplexity:5 */
var ex = function(extension) {
var extendedObject;
if (extension.property) {
if (!webu[extension.property]) {
webu[extension.property] = {};
}
extendedObject = webu[extension.property];
} else {
extendedObject = webu;
}
if (extension.methods) {
extension.methods.forEach(function(method) {
method.attachToObject(extendedObject);
method.setRequestManager(webu._requestManager);
});
}
if (extension.properties) {
extension.properties.forEach(function(property) {
property.attachToObject(extendedObject);
property.setRequestManager(webu._requestManager);
});
}
};
ex.formatters = formatters;
ex.utils = utils;
ex.Method = Method;
ex.Property = Property;
return ex;
};
module.exports = extend;