mirror of
https://github.com/storybookjs/storybook.git
synced 2025-03-28 05:10:17 +08:00
skip serializing (Synthetic)Events
This commit is contained in:
parent
7ef5e392ce
commit
89d400e8a7
@ -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';
|
||||
|
13
addons/actions/src/lib/util/prepareArguments.js
Normal file
13
addons/actions/src/lib/util/prepareArguments.js
Normal 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.
|
||||
}
|
||||
}
|
@ -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, {
|
||||
|
Loading…
x
Reference in New Issue
Block a user