Skip to content

Commit

Permalink
Allow passing instace of service directly to client
Browse files Browse the repository at this point in the history
  • Loading branch information
SomeoneWeird committed Dec 21, 2016
1 parent 64c6023 commit bf85f33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/client.js
Expand Up @@ -7,6 +7,9 @@ const async = require('async')
const bluebird = require('bluebird')
const utils = require('ht-utils')

const Service = require('./service')
const LocalTransport = require('./transports').Local

let Client = function Client (services) {
if (!(this instanceof Client)) {
return new Client(services)
Expand Down Expand Up @@ -35,6 +38,11 @@ Client.prototype.add = function (name, transport) {
if (this.services[name]) {
throw new Error('Tried adding a service with duplicate name')
}
if (transport instanceof Service) {
let service = transport
transport = new LocalTransport()
service.addTransport(transport)
}
this.services[name] = transport
let client = new transport.Client()
this.connections[name] = client
Expand Down
8 changes: 8 additions & 0 deletions test/client.js
Expand Up @@ -6,6 +6,7 @@ const s = require("ht-schema");
const bluebird = require("bluebird");

const Client = require("../src/client");
const Service = require("../src/service");

const _data = {
hello: "world"
Expand Down Expand Up @@ -163,6 +164,13 @@ describe("Client", function() {
assert.equal(Object.keys(client.connections).length, countBefore+1);
});

it("should allow adding a service directly", function () {
let client = new Client();
let service = new Service()
client.add('myService', service)
assert.deepEqual(Object.keys(client.connections), [ 'myService' ]);
});

});

describe("call", function() {
Expand Down

0 comments on commit bf85f33

Please sign in to comment.