Skip to content

Commit

Permalink
Avoid JSON stringifying React SyntheticEvents. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoda committed Mar 25, 2016
1 parent b59b082 commit 36560e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dist/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ function action(name) {
var _getData$actions = _getData.actions;
var actions = _getData$actions === undefined ? [] : _getData$actions;

// Remove events from the args. Otherwise, it creates a huge JSON string.

if (args[0] && args[0].constructor && /Synthetic/.test(args[0].constructor.name)) {
args[0] = '[' + args[0].constructor.name + ']';
}

actions = [{ name: name, args: args }].concat(actions.slice(0, 5));
(0, _data.setData)({ actions: actions });
};
Expand Down
10 changes: 10 additions & 0 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export function storiesOf(kind, m) {
export function action(name) {
return function(...args) {
let {actions = []} = getData();

// Remove events from the args. Otherwise, it creates a huge JSON string.
if (
args[0] &&
args[0].constructor &&
/Synthetic/.test(args[0].constructor.name)
) {
args[0] = `[${args[0].constructor.name}]`;
}

actions = [{name, args}].concat(actions.slice(0, 5));
setData({actions});
}
Expand Down

0 comments on commit 36560e4

Please sign in to comment.