Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(transport-commons): Crow - fix array dispatching #3073

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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