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

Correctly detect and handle undefined/null in action calls #133

Merged
merged 1 commit into from
Apr 21, 2016
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 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