procnet
v1.2.6
Published
A tool for service oriented architecture or dependency injection.
Downloads
4
Maintainers
Readme
Procnet
A remote provider built for use with pogostick (although you could use a different rpc library).
Define Services
Seperate network code from your service definition.
// For example a `math` service
module.exports = procnet.service(function() {
return {
add: function(a, b) {
return a + b;
},
multiply: function(a, b) {
return a * b;
}
}
});
Compose Services
// An example `rectangle` service.
module.exports = procnet.service(['math'], function(math) {
return {
surface: function(h, w) {
return math.multiply(h, w);
}
};
});
Unit Test Services
One of the benefit of seperating your logic this way is the way it permits you to unit test your services, mocking dependencies.
// You can pick any promise library you want, just need to provide a factory function.
var mock = procnet.mocker(promiseFactory);
var mocked = mock({
math: {
// Our fake multiply always returns 1 instead
multiply: function() { return 1; }
}
}, rectangle);
mocked
.surface(2, 2)
.then(function(r) {
assert.equal(r, 1);
});