This package is used for storing any values or dependecies that any parts of the application might need.
npm install node-hexconnector
var HexConnector = require('node-hexconnector');
var cn = new HexConnector();
cn._set('key', 'any kind of value');
var myValue = cn._get('key');
console.log(myValue);
cn.registerAdapter('ownLib', {
testFunc: function () {
console.log('OK');
}
});
cn.adapters.ownLib.testFunc();
cn.registerAdapter('myUtil', 'util');
cn.adapters.myUtil.isBoolean(true);
Let's see our adapter (own.js)
var connector;
var config;
module.exports = {
initAdapter: function (_connector, _config) {
connector = _connector;
config = _config;
},
getConfig: function() {
return config;
}
}
Now, let's see how to use it...
cn.registerAdapter('ownAdapter', './own');
var adapterConfig = cn.adapters.ownAdapter.getConfig();
console.log(adapterConfig);
... or register and use the adapters with lazy initialization...
cn.registerAdapter('ownAdapter', './own', {test_key: 'test value'}, true);
var adapter = cn.getAdapter('ownAdapter');
console.log(adapter.getConfig());