Skip to content

Commit

Permalink
fix: Compare socket event data using lodash's isEqual instead of inde…
Browse files Browse the repository at this point in the history
…xOf (#1061)

Using indexOf will return false when comparing identical objects with different references. This in turn breaks feathers-sync since it creates a new object using JSON.parse, meaning that data won't properly sent out when for example patching multiple rows at once.
  • Loading branch information
rlunden authored and daffl committed Oct 25, 2018
1 parent ef46002 commit f706db3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/transport-commons/lib/socket/utils.js
@@ -1,5 +1,6 @@
const errors = require('@feathersjs/errors');
const debug = require('debug')('@feathersjs/transport-commons');
const { isEqual } = require('lodash');

const paramsPositions = exports.paramsPositions = {
find: 0,
Expand Down Expand Up @@ -46,7 +47,7 @@ exports.getDispatcher = function (emit, socketKey) {
// 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 = result[context.result.indexOf(data)];
result = context.result.find(resultData => isEqual(resultData, data));
}

debug(`Dispatching '${eventName}' to Socket ${socket.id} with`, result);
Expand Down

0 comments on commit f706db3

Please sign in to comment.