From 70a82a60d1a699005e00c79be23caf8f2c15e6ee Mon Sep 17 00:00:00 2001 From: Ashley Blurton Date: Thu, 21 Apr 2016 14:21:12 +0100 Subject: [PATCH 1/2] Check for events passed to action() in all arguments, rather than just the first --- dist/client/client_api.js | 9 ++++++--- src/client/client_api.js | 14 +++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/dist/client/client_api.js b/dist/client/client_api.js index 7dd5d12c8bdf..175603ca9a5a 100644 --- a/dist/client/client_api.js +++ b/dist/client/client_api.js @@ -89,9 +89,12 @@ var ClientApi = function () { // Remove events from the args. Otherwise, it creates a huge JSON string. - if (args[0] && typeof args[0].preventDefault === 'function') { - args[0] = '[SyntheticEvent]'; - } + args = args.map(function (arg) { + if (typeof arg.preventDefault === 'function') { + return '[SyntheticEvent]'; + } + return arg; + }); var id = ++idGenerator; var data = { name: name, args: args }; diff --git a/src/client/client_api.js b/src/client/client_api.js index 6a1bdfa22981..b3911f907e87 100644 --- a/src/client/client_api.js +++ b/src/client/client_api.js @@ -42,16 +42,16 @@ export default class ClientApi { const syncedStore = this._syncedStore; return function (..._args) { - const args = Array.from(_args); + let args = Array.from(_args); let { actions = [] } = syncedStore.getData(); // Remove events from the args. Otherwise, it creates a huge JSON string. - if ( - args[0] && - typeof args[0].preventDefault === 'function' - ) { - args[0] = '[SyntheticEvent]'; - } + args = args.map(arg => { + if (typeof arg.preventDefault === 'function') { + return '[SyntheticEvent]'; + } + return arg; + }); const id = ++idGenerator; const data = { name, args }; From e2ed55e9ddcd5f2bb3562f52b7be9b787588d75f Mon Sep 17 00:00:00 2001 From: Ashley Blurton Date: Thu, 21 Apr 2016 16:06:20 +0100 Subject: [PATCH 2/2] Add test case for new event serialization --- src/client/__tests__/client_api.js | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/client/__tests__/client_api.js b/src/client/__tests__/client_api.js index 55a5aa3d3289..700dd81535a0 100644 --- a/src/client/__tests__/client_api.js +++ b/src/client/__tests__/client_api.js @@ -162,6 +162,38 @@ describe('client.ClientApi', () => { count: 1, }]); }); + + it('should replace any Synthetic Event with it\'s name when not the first argument', () => { + const api = getClientApi(); + api._syncedStore.getData = () => ({ actions: [] }); + api._syncedStore.setData = sinon.stub(); + + const event = { + preventDefault() {}, + }; + const data = { + type: 'delete', + }; + + const cb = api.action('hello'); + cb(data, event); + + const args = api._syncedStore.setData.args[0]; + const actions = clearActionId(args[0].actions); + + expect(actions).to.be.deep.equal([{ + data: { + name: 'hello', + args: [ + { + type: 'delete', + }, + '[SyntheticEvent]', + ], + }, + count: 1, + }]); + }); }); describe('linkTo', () => {