Skip to content

Commit

Permalink
fix(transport-commons): Crow - fix array dispatching (#3073)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Feb 24, 2023
1 parent f5f7fae commit 1936c64
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/transport-commons/src/socket/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function getDispatcher (emit: string, socketMap: WeakMap<RealTimeConnecti
// If we are getting events from an array but try to dispatch individual data
// try to get the individual item to dispatch from the correct index.
if (!Array.isArray(data) && Array.isArray(context.result) && Array.isArray(result)) {
result = context.result.find(resultData => isEqual(resultData, data));
result = result.find(resultData => isEqual(resultData, data));
}

debug(`Dispatching '${eventName}' to Socket ${socket.id} with`, result);
Expand Down
19 changes: 19 additions & 0 deletions packages/transport-commons/test/socket/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,25 @@ describe('socket commons utils', () => {
dispatcher('testing', dummyChannel, dummyHook, data2);
});

it('dispatches dispatch arrays properly', done => {
const data1 = { message: 'First message' };
const data2 = { message: 'Second message' };

dummyHook.result = []
dummyHook.dispatch = [ data1, data2 ];

dummySocket.once('testing', data => {
assert.deepStrictEqual(data, data1);
dummySocket.once('testing', result => {
assert.deepStrictEqual(result, data2);
done();
});
});

dispatcher('testing', dummyChannel, dummyHook, data1);
dispatcher('testing', dummyChannel, dummyHook, data2);
});

it('dispatches arrays properly for custom events', done => {
const result = [
{ message: 'First' },
Expand Down

0 comments on commit 1936c64

Please sign in to comment.