Skip to content

Commit

Permalink
Correctly detect and handle undefined/null in action calls (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Blurton authored and arunoda committed Apr 21, 2016
1 parent a5dccb9 commit e6fc05d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/client/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var ClientApi = function () {
// Remove events from the args. Otherwise, it creates a huge JSON string.

args = args.map(function (arg) {
if (typeof arg.preventDefault === 'function') {
if (arg && typeof arg.preventDefault === 'function') {
return '[SyntheticEvent]';
}
return arg;
Expand Down
19 changes: 19 additions & 0 deletions src/client/__tests__/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ describe('client.ClientApi', () => {
}]);
});

it('should accept null and undefined values', () => {
const api = getClientApi();
api._syncedStore.getData = () => ({ actions: [] });
api._syncedStore.setData = sinon.stub();

const cb = api.action('hello');
cb(null, void 0);

const args = api._syncedStore.setData.args[0];
const actions = clearActionId(args[0].actions);
expect(actions).to.be.deep.equal([{
data: {
name: 'hello',
args: [null, void 0],
},
count: 1,
}]);
});

it('should only keep the latest 10 actions in the syncedStore', () => {
const api = getClientApi();
api._syncedStore.getData = () => ({
Expand Down
2 changes: 1 addition & 1 deletion src/client/client_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class ClientApi {

// Remove events from the args. Otherwise, it creates a huge JSON string.
args = args.map(arg => {
if (typeof arg.preventDefault === 'function') {
if (arg && typeof arg.preventDefault === 'function') {
return '[SyntheticEvent]';
}
return arg;
Expand Down

0 comments on commit e6fc05d

Please sign in to comment.