Skip to content

Commit

Permalink
fix(transport-commons): Allow to properly chain SocketIo client.off (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Nov 27, 2019
1 parent 2331c2a commit a4aecbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion packages/transport-commons/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ export class Service {
// of the emitter-component Socket.io is using
off (name: string, ...args: any[]) {
if (typeof this.connection.off === 'function') {
return this.connection.off(`${this.path} ${name}`, ...args);
const result = this.connection.off(`${this.path} ${name}`, ...args);

return result === this.connection ? this : result;
} else if (args.length === 0) {
// @ts-ignore
return this.removeAllListeners(name);
Expand Down
9 changes: 5 additions & 4 deletions packages/transport-commons/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,15 @@ describe('client', () => {
connection.emit('todos test', testing);
});

it('forwards namespaced call to .off', done => {
it('forwards namespaced call to .off, returns service instance', () => {
// Use it's own connection and service so off method gets detected
const conn = new EventEmitter();

// @ts-ignore
conn.off = name => {
conn.off = function (name) {
assert.strictEqual(name, 'todos test');
done();

return this;
};

const client = new Service({
Expand All @@ -221,6 +222,6 @@ describe('client', () => {
connection: conn
});

client.off('test');
assert.strictEqual(client.off('test'), client);
});
});

0 comments on commit a4aecbc

Please sign in to comment.