Skip to content

Commit

Permalink
Addon-actions: display enumerable properties from prototype chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypnosphi committed Nov 29, 2017
1 parent 8ac2dfe commit bcbeffa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
7 changes: 5 additions & 2 deletions addons/actions/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,12 @@ export function decycle(object, depth = 15) {
} else {
obj = { [CLASS_NAME_KEY]: value.constructor ? value.constructor.name : 'Object' };

Object.keys(value).forEach(name => {
// We want to iterate over all the enumerable properties, including the ones in prototype chain
// eslint-disable-next-line no-restricted-syntax, guard-for-in
for (const name in value) {
// noinspection JSUnfilteredForInLoop
obj[name] = derez(value[name], `${path}[${JSON.stringify(name)}]`, _depth + 1);
});
}
}

if (_depth === 0 && isObject(value) && isCyclic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Storyshots Addon Actions Circular Payload 1`] = `
<button
className="css-1yjiefr"
onClick={[Function]}
>
Circular Payload
</button>
`;

exports[`Storyshots Addon Actions Decorated Action 1`] = `
<button
className="css-1yjiefr"
onClick={[Function]}
>
First Argument
</button>
`;

exports[`Storyshots Addon Actions File object as payload 1`] = `
<button
className="css-1yjiefr"
onClick={[Function]}
>
File
</button>
`;

exports[`Storyshots Addon Actions Function Name 1`] = `
<button
className="css-1yjiefr"
onClick={[Function]}
>
Action.name:
fnName
</button>
`;

exports[`Storyshots Addon Actions Hello World 1`] = `
<button
className="css-1yjiefr"
onClick={[Function]}
>
Hello World
</button>
`;

exports[`Storyshots Addon Actions Reserved keyword as name 1`] = `
<button
className="css-1yjiefr"
onClick={[Function]}
>
Delete
</button>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { storiesOf } from '@storybook/react';
import { action, decorateAction } from '@storybook/addon-actions';
import { Button } from '@storybook/react/demo';
import { File } from 'global';

const pickFirst = decorateAction([args => args.slice(0, 1)]);

Expand All @@ -17,4 +18,8 @@ storiesOf('Addon Actions', module)
const fn = action('fnName');
return <Button onClick={fn}>Action.name: {fn.name}</Button>;
})
.add('Reserved keyword as name', () => <Button onClick={action('delete')}>Delete</Button>);
.add('Reserved keyword as name', () => <Button onClick={action('delete')}>Delete</Button>)
.add('File object as payload', () => {
const file = new File([''], 'filename.txt', { type: 'text/plain', lastModified: new Date() });
return <Button onClick={() => action('file')(file)}>File</Button>;
});

0 comments on commit bcbeffa

Please sign in to comment.