skip serializing (Synthetic)Events

This commit is contained in:
Rob Halff 2018-01-03 03:30:35 +00:00
parent 7ef5e392ce
commit 89d400e8a7
3 changed files with 16 additions and 15 deletions

View File

@ -2,5 +2,6 @@ export canConfigureName from './canConfigureName.js';
export getPropertiesList from './getPropertiesList.js';
export isObject from './isObject.js';
export muteProperty from './muteProperty.js';
export prepareArguments from './prepareArguments';
export typeReviver from './typeReviver.js';
export typeReplacer from './typeReplacer.js';

View File

@ -0,0 +1,13 @@
import { decycle } from '../index';
export default function prepareArguments(arg) {
if (arg && typeof arg.preventDefault !== 'undefined') {
return JSON.stringify(`[${arg.constructor.name}]`);
}
try {
return JSON.stringify(decycle(arg));
} catch (error) {
return error.toString(); // IE still cyclic.
}
}

View File

@ -3,25 +3,12 @@
import addons from '@storybook/addons';
import uuid from 'uuid/v1';
import { EVENT_ID } from './';
import { decycle } from './lib';
import { canConfigureName } from './lib/util';
import { canConfigureName, prepareArguments } from './lib/util';
export function action(name) {
// eslint-disable-next-line no-shadow
const handler = function action(..._args) {
const args = _args.map(arg => {
let result;
try {
result = JSON.stringify(decycle(arg));
} catch (error) {
// IE still cyclic.
return JSON.stringify(error.toString());
}
return result;
});
const args = _args.map(prepareArguments);
const channel = addons.getChannel();
const id = uuid();
channel.emit(EVENT_ID, {