Skip to content

Commit

Permalink
Merge pull request #6 from kadirahq/safe-stringify
Browse files Browse the repository at this point in the history
Support circular reference arguments
  • Loading branch information
Muhammed Thanish authored Sep 10, 2016
2 parents 14a0078 + 2bb66b6 commit 1473682
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
14 changes: 11 additions & 3 deletions .storybook/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,16 @@ const pickFirst = decorateAction([

storiesOf('Button', module)
.add('Hello World', () => (
<button onClick={action('Hello World')}>Hello World</button>
<button onClick={action('hello-world')}>Hello World</button>
))
.add('Decorated Action', () => (
<button onClick={pickFirst('First Argument')}>First Argument</button>
));
<button onClick={pickFirst('decorated')}>First Argument</button>
))
.add('Circular Payload', () => {
const circular = {foo: {}};
circular.foo.circular = circular;
return <button
onClick={() => action('circular')(circular)}>
Circular Payload
</button>;
});
3 changes: 3 additions & 0 deletions dist/containers/ActionLogger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ var ActionLogger = function (_React$Component) {
_createClass(ActionLogger, [{
key: 'addAction',
value: function addAction(action) {
action.data.args = action.data.args.map(function (arg) {
return JSON.parse(arg);
});
var actions = [].concat(_toConsumableArray(this.state.actions));
var previous = actions.length && actions[0];
if (previous && (0, _deepEqual2.default)(previous.data, action.data)) {
Expand Down
8 changes: 6 additions & 2 deletions dist/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var _storybookAddons = require('@kadira/storybook-addons');

var _storybookAddons2 = _interopRequireDefault(_storybookAddons);

var _jsonStringifySafe = require('json-stringify-safe');

var _jsonStringifySafe2 = _interopRequireDefault(_jsonStringifySafe);

var _ = require('./');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
Expand All @@ -18,9 +22,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr

function _format(arg) {
if (arg && typeof arg.preventDefault !== 'undefined') {
return '[SyntheticEvent]';
return (0, _jsonStringifySafe2.default)('[SyntheticEvent]');
}
return arg;
return (0, _jsonStringifySafe2.default)(arg);
}

function action(name) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"deep-equal": "^1.0.1",
"json-stringify-safe": "^5.0.1",
"react-inspector": "^1.1.0"
},
"peerDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/containers/ActionLogger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class ActionLogger extends React.Component {
}

addAction(action) {
action.data.args = action.data.args.map(arg => JSON.parse(arg));
const actions = [...this.state.actions];
const previous = actions.length && actions[0];
if (previous && deepEqual(previous.data, action.data)) {
Expand Down
5 changes: 3 additions & 2 deletions src/preview.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import addons from '@kadira/storybook-addons';
import stringify from 'json-stringify-safe';
import { EVENT_ID } from './';

function _format(arg) {
if (arg && typeof arg.preventDefault !== 'undefined') {
return '[SyntheticEvent]';
return stringify('[SyntheticEvent]');
}
return arg;
return stringify(arg);
}

export function action(name) {
Expand Down

0 comments on commit 1473682

Please sign in to comment.