@storybook/addon-actions
Advanced tools
Comparing version 3.3.0-alpha.4 to 3.3.0-alpha.5
@@ -43,4 +43,6 @@ 'use strict'; | ||
var _util = require('../../util'); | ||
var _lib = require('../../lib'); | ||
var _util = require('../../lib/util'); | ||
var _ActionLogger = require('../../components/ActionLogger/'); | ||
@@ -54,4 +56,2 @@ | ||
/* eslint-disable no-underscore-dangle */ | ||
var ActionLogger = function (_React$Component) { | ||
@@ -92,6 +92,6 @@ (0, _inherits3.default)(ActionLogger, _React$Component); | ||
action.data.args = action.data.args.map(function (arg) { | ||
return (0, _util.retrocycle)(arg); | ||
return (0, _lib.retrocycle)(arg); | ||
}); // eslint-disable-line | ||
var isCyclic = !!action.data.args.find(function (arg) { | ||
return (0, _util.isObject)(arg) && arg[_util.CYCLIC_KEY]; | ||
return (0, _util.isObject)(arg) && arg[_lib.CYCLIC_KEY]; | ||
}); | ||
@@ -129,3 +129,3 @@ var actions = [].concat((0, _toConsumableArray3.default)(this.state.actions)); | ||
return ActionLogger; | ||
}(_react2.default.Component); | ||
}(_react2.default.Component); /* eslint-disable no-underscore-dangle */ | ||
@@ -132,0 +132,0 @@ exports.default = ActionLogger; |
@@ -15,6 +15,2 @@ 'use strict'; | ||
var _from = require('babel-runtime/core-js/array/from'); | ||
var _from2 = _interopRequireDefault(_from); | ||
exports.action = action; | ||
@@ -33,11 +29,11 @@ exports.decorateAction = decorateAction; | ||
var _util = require('./util'); | ||
var _lib = require('./lib'); | ||
var _util = require('./lib/util'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* eslint-disable no-underscore-dangle */ | ||
function action(name) { | ||
// eslint-disable-next-line no-unused-vars, func-names | ||
var handler = function handler() { | ||
// eslint-disable-next-line no-shadow | ||
var handler = function action() { | ||
for (var _len = arguments.length, _args = Array(_len), _key = 0; _key < _len; _key++) { | ||
@@ -47,4 +43,14 @@ _args[_key] = arguments[_key]; | ||
var args = (0, _from2.default)(_args).map(function (arg) { | ||
return (0, _stringify2.default)((0, _util.decycle)(arg)); | ||
var args = _args.map(function (arg) { | ||
var result = void 0; | ||
try { | ||
result = (0, _stringify2.default)((0, _lib.decycle)(arg)); | ||
} catch (error) { | ||
// IE still cyclic. | ||
return (0, _stringify2.default)(error.toString()); | ||
} | ||
return result; | ||
}); | ||
@@ -59,6 +65,7 @@ var channel = _addons2.default.getChannel(); | ||
var fnName = name && typeof name === 'string' ? name.replace(/\W+/g, '_') : 'action'; | ||
Object.defineProperty(handler, 'name', { value: fnName }); | ||
if (_util.canConfigureName && name && typeof name === 'string') { | ||
Object.defineProperty(handler, 'name', { value: name }); | ||
} | ||
return handler; | ||
} | ||
} /* eslint-disable no-underscore-dangle */ | ||
@@ -65,0 +72,0 @@ function decorateAction(decorators) { |
{ | ||
"name": "@storybook/addon-actions", | ||
"version": "3.3.0-alpha.4", | ||
"version": "3.3.0-alpha.5", | ||
"description": "Action Logger addon for storybook", | ||
@@ -19,14 +19,14 @@ "keywords": [ | ||
"scripts": { | ||
"deploy-storybook": "storybook-to-ghpages", | ||
"prepare": "node ../../scripts/prepare.js", | ||
"storybook": "start-storybook -p 9001" | ||
"prepare": "node ../../scripts/prepare.js" | ||
}, | ||
"dependencies": { | ||
"@storybook/addons": "^3.3.0-alpha.4", | ||
"deep-equal": "^1.0.1", | ||
"global": "^4.3.2", | ||
"make-error": "^1.3.0", | ||
"prop-types": "^15.6.0", | ||
"react-inspector": "^2.2.1", | ||
"react-inspector": "^2.2.2", | ||
"uuid": "^3.1.0" | ||
}, | ||
"peerDependencies": { | ||
"@storybook/addons": "^3.3.0-alpha.4", | ||
"react": "*", | ||
@@ -33,0 +33,0 @@ "react-dom": "*" |
@@ -6,3 +6,3 @@ # Storybook Addon Actions | ||
[![Known Vulnerabilities](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847/badge.svg)](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847) | ||
[![BCH compliance](https://bettercodehub.com/edge/badge/storybooks/storybook)](https://bettercodehub.com/results/storybooks/storybook) [![codecov](https://codecov.io/gh/storybooks/storybook/branch/master/graph/badge.svg)](https://codecov.io/gh/storybooks/storybook) | ||
[![BCH compliance](https://bettercodehub.com/edge/badge/storybooks/storybook)](https://bettercodehub.com/results/storybooks/storybook) [![codecov](https://codecov.io/gh/storybooks/storybook/branch/master/graph/badge.svg)](https://codecov.io/gh/storybooks/storybook) | ||
[![Storybook Slack](https://now-examples-slackin-nqnzoygycp.now.sh/badge.svg)](https://now-examples-slackin-nqnzoygycp.now.sh/) | ||
@@ -61,3 +61,3 @@ [![Backers on Open Collective](https://opencollective.com/storybook/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/storybook/sponsors/badge.svg)](#sponsors) | ||
```js | ||
import { action, decorateAction } from '@storybook/addon-actions' | ||
import { decorateAction } from '@storybook/addon-actions'; | ||
@@ -64,0 +64,0 @@ import Button from './button'; |
@@ -6,3 +6,4 @@ /* eslint-disable no-underscore-dangle */ | ||
import deepEqual from 'deep-equal'; | ||
import { CYCLIC_KEY, isObject, retrocycle } from '../../util'; | ||
import { CYCLIC_KEY, retrocycle } from '../../lib'; | ||
import { isObject } from '../../lib/util'; | ||
@@ -9,0 +10,0 @@ import ActionLoggerComponent from '../../components/ActionLogger/'; |
@@ -6,8 +6,21 @@ /* eslint-disable no-underscore-dangle */ | ||
import { EVENT_ID } from './'; | ||
import { decycle } from './util'; | ||
import { decycle } from './lib'; | ||
import { canConfigureName } from './lib/util'; | ||
export function action(name) { | ||
// eslint-disable-next-line no-unused-vars, func-names | ||
const handler = function(..._args) { | ||
const args = Array.from(_args).map(arg => JSON.stringify(decycle(arg))); | ||
// 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 channel = addons.getChannel(); | ||
@@ -21,4 +34,5 @@ const id = uuid(); | ||
const fnName = name && typeof name === 'string' ? name.replace(/\W+/g, '_') : 'action'; | ||
Object.defineProperty(handler, 'name', { value: fnName }); | ||
if (canConfigureName && name && typeof name === 'string') { | ||
Object.defineProperty(handler, 'name', { value: name }); | ||
} | ||
return handler; | ||
@@ -25,0 +39,0 @@ } |
import addons from '@storybook/addons'; | ||
import uuid from 'uuid/v1'; | ||
import { action } from './preview'; | ||
import { undefinedType, symbolType } from './lib/types'; | ||
@@ -38,3 +39,75 @@ jest.mock('uuid/v1'); | ||
}); | ||
it('should be able to handle non plain object', () => { | ||
function A(val) { | ||
this.a = val; | ||
} | ||
const a = new A('b'); | ||
const channel = { emit: jest.fn() }; | ||
addons.getChannel.mockReturnValue(channel); | ||
action('foo')(a); | ||
expect(JSON.parse(channel.emit.mock.calls[0][1].data.args[0])).toEqual({ | ||
'$___storybook.objectName': 'A', | ||
a: 'b', | ||
}); | ||
}); | ||
it('should be able to handle non plain cyclic object', () => { | ||
function A() {} | ||
const a = new A(); | ||
a.a = a; | ||
const channel = { emit: jest.fn() }; | ||
addons.getChannel.mockReturnValue(channel); | ||
action('foo')(a); | ||
expect(JSON.parse(channel.emit.mock.calls[0][1].data.args[0])).toEqual({ | ||
'$___storybook.objectName': 'A', | ||
'$___storybook.isCyclic': true, | ||
a: { | ||
$ref: '$', | ||
}, | ||
}); | ||
}); | ||
describe('should be able to emit primitive value type:', () => { | ||
[true, false, null, 10, 'a'].forEach(value => { | ||
it(`${typeof value} value ${JSON.stringify(value)}`, () => { | ||
const channel = { emit: jest.fn() }; | ||
addons.getChannel.mockReturnValue(channel); | ||
action('foo')(value); | ||
expect(JSON.parse(channel.emit.mock.calls[0][1].data.args[0])).toBe(value); | ||
}); | ||
}); | ||
it('undefined value', () => { | ||
const channel = { emit: jest.fn() }; | ||
addons.getChannel.mockReturnValue(channel); | ||
action('foo')(undefined); | ||
expect(JSON.parse(channel.emit.mock.calls[0][1].data.args[0])).toEqual({ | ||
[undefinedType.KEY]: true, | ||
}); | ||
}); | ||
it('symbol value', () => { | ||
const channel = { emit: jest.fn() }; | ||
addons.getChannel.mockReturnValue(channel); | ||
action('foo')(Symbol('A Symbol')); | ||
expect(JSON.parse(channel.emit.mock.calls[0][1].data.args[0])).toEqual({ | ||
[symbolType.KEY]: 'A Symbol', | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
242034
101
2031
9
7
+ Addedglobal@^4.3.2
+ Addedmake-error@^1.3.0
+ Addeddom-walk@0.1.2(transitive)
+ Addedglobal@4.4.0(transitive)
+ Addedmake-error@1.3.6(transitive)
+ Addedmin-document@2.19.0(transitive)
+ Addedprocess@0.11.10(transitive)
- Removed@storybook/addons@^3.3.0-alpha.4
Updatedreact-inspector@^2.2.2