Skip to content

Commit

Permalink
lib: change event signature
Browse files Browse the repository at this point in the history
Changes event message signature to always send an array
of arbitrary arguments. This makes it work same way as
EventEmitter does and also makes its usage similar to
call action.

PR-URL: metarhia/jstp#187
Fixes: metarhia/jstp#134
Fixes: metarhia/jstp#162
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Mykola Bilochub <nbelochub@gmail.com>
  • Loading branch information
lundibundi committed May 30, 2017
1 parent ae5e2ff commit 92cb487
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/unit/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ describe('JSTP Connection', () => {

describe('event', () => {
testPacketSending('event', (connection, transport) => {
const eventArgs = { arg: 'value' };
const eventArgs = [ 'value' ];

const sendSpy = chai.spy((data) => {
const packet = jstp.parse(data);
Expand Down
10 changes: 5 additions & 5 deletions test/unit/remote-proxy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('RemoteProxy', () => {
emitRemoteEvent() { },

processEventPacket() {
proxy.emit('testEvent', 'payload', true);
proxy._emitLocal('testEvent', ['payload1', 'payload2']);
}
};

Expand Down Expand Up @@ -64,22 +64,22 @@ describe('RemoteProxy', () => {
it('must emit events through the network and locally', () => {
const handler = chai.spy();
proxy.on('testEvent', handler);
proxy.emit('testEvent', 'payload');
proxy.emit('testEvent', 'payload1', 'payload2');

expect(eventSpy).to.have.been.called.exactly(1);
expect(eventSpy).to.have.been.called.with(
'testInterface', 'testEvent', 'payload');
'testInterface', 'testEvent', ['payload1', 'payload2']);

expect(handler).to.have.been.called.exactly(1);
expect(handler).to.have.been.called.with('payload');
expect(handler).to.have.been.called.with('payload1', 'payload2');
});

it('must not re-emit events back', () => {
const handler = chai.spy();
proxy.on('testEvent', handler);
connectionMock.processEventPacket();

expect(handler).to.have.been.called.with('payload');
expect(handler).to.have.been.called.with('payload1', 'payload2');
expect(eventSpy).to.not.have.been.called();
});
});

0 comments on commit 92cb487

Please sign in to comment.