@dump247/storybook-state
Advanced tools
Comparing version 1.0.5 to 1.1.0
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
@@ -24,5 +22,5 @@ | ||
var _v = require('uuid/v4'); | ||
var _addons = require('@storybook/addons'); | ||
var _v2 = _interopRequireDefault(_v); | ||
var _addons2 = _interopRequireDefault(_addons); | ||
@@ -63,39 +61,12 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
value: function subscribe(handler) { | ||
var subscriptionId = (0, _v2.default)(); | ||
this.handlers.push({ handler: handler, subscriptionId: subscriptionId }); | ||
return subscriptionId; | ||
if (this.handlers.indexOf(handler) < 0) { | ||
this.handlers.push(handler); | ||
} | ||
} | ||
}, { | ||
key: 'unsubscribe', | ||
value: function unsubscribe(subscriptionId) { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = this.handlers.entries()[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var _step$value = _slicedToArray(_step.value, 2), | ||
index = _step$value[0], | ||
handlerId = _step$value[1].subscriptionId; | ||
if (handlerId === subscriptionId) { | ||
this.handlers.splice(index, 1); | ||
break; | ||
} | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
value: function unsubscribe(handler) { | ||
var handlerIndex = this.handlers.indexOf(handler); | ||
if (handlerIndex >= 0) { | ||
this.handlers.splice(handlerIndex, 1); | ||
} | ||
@@ -108,4 +79,3 @@ } | ||
this.handlers.forEach(function (_ref) { | ||
var handler = _ref.handler; | ||
this.handlers.forEach(function (handler) { | ||
return handler(state); | ||
@@ -123,3 +93,3 @@ }); | ||
function StoryState() { | ||
var _ref2; | ||
var _ref; | ||
@@ -134,4 +104,15 @@ var _temp, _this, _ret; | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref2 = StoryState.__proto__ || Object.getPrototypeOf(StoryState)).call.apply(_ref2, [this].concat(args))), _this), _this.state = { | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = StoryState.__proto__ || Object.getPrototypeOf(StoryState)).call.apply(_ref, [this].concat(args))), _this), _this.state = { | ||
storyState: _this.props.store.state | ||
}, _this.handleResetEvent = function () { | ||
var store = _this.props.store; | ||
store.reset(); | ||
}, _this.handleStateChange = function (storyState) { | ||
var channel = _this.props.channel; | ||
_this.setState({ storyState: storyState }); | ||
channel.emit('dump247/state/change', storyState); | ||
}, _temp), _possibleConstructorReturn(_this, _ret); | ||
@@ -143,10 +124,10 @@ } | ||
value: function componentDidMount() { | ||
var _this2 = this; | ||
var _props = this.props, | ||
store = _props.store, | ||
channel = _props.channel; | ||
var store = this.props.store; | ||
this.subscriptionId = store.subscribe(function (storyState) { | ||
return _this2.setState({ storyState: storyState }); | ||
}); | ||
store.subscribe(this.handleStateChange); | ||
channel.on('dump247/state/reset', this.handleResetEvent); | ||
channel.emit('dump247/state/change', store.state); | ||
} | ||
@@ -156,6 +137,9 @@ }, { | ||
value: function componentWillUnmount() { | ||
var store = this.props.store; | ||
var _props2 = this.props, | ||
store = _props2.store, | ||
channel = _props2.channel; | ||
store.unsubscribe(this.subscriptionId); | ||
store.unsubscribe(this.handleStateChange); | ||
channel.removeListener('dump247/state/reset', this.handleResetEvent); | ||
} | ||
@@ -165,5 +149,5 @@ }, { | ||
value: function render() { | ||
var _props = this.props, | ||
store = _props.store, | ||
storyFn = _props.storyFn; | ||
var _props3 = this.props, | ||
store = _props3.store, | ||
storyFn = _props3.storyFn; | ||
@@ -180,6 +164,7 @@ | ||
var store = new Store(initialState || {}); | ||
var channel = _addons2.default.getChannel(); | ||
return function () { | ||
return _react2.default.createElement(StoryState, { store: store, storyFn: storyFn }); | ||
return _react2.default.createElement(StoryState, { store: store, storyFn: storyFn, channel: channel }); | ||
}; | ||
} |
{ | ||
"name": "@dump247/storybook-state", | ||
"version": "1.0.5", | ||
"version": "1.1.0", | ||
"description": "Manage component state in storybook stories.", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "babel index.js --out-dir dist", | ||
"test": "jest" | ||
"build": "cd src/ && babel index.js register.js --out-dir ../dist", | ||
"dist": "npm publish", | ||
"test": "jest", | ||
"storybook": "start-storybook -p 9001 -c .storybook" | ||
}, | ||
@@ -32,7 +34,6 @@ "repository": { | ||
"dependencies": { | ||
"prop-types": "^15.6.0", | ||
"react": "^15.6.0", | ||
"uuid": "^3.1.0" | ||
"@storybook/addons": "^3.2.16" | ||
}, | ||
"devDependencies": { | ||
"@storybook/react": "^3.2.16", | ||
"babel-cli": "^6.26.0", | ||
@@ -39,0 +40,0 @@ "babel-plugin-transform-react-remove-prop-types": "^0.4.10", |
@@ -1,1 +0,1 @@ | ||
// Nothing to do here. This file exists for future proofing. Maybe will add some stuff later. | ||
require('./dist/register').register(); |
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
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
203097
3
14
5575
11
+ Added@storybook/addons@^3.2.16
+ Added@storybook/addons@3.4.12(transitive)
- Removedprop-types@^15.6.0
- Removedreact@^15.6.0
- Removeduuid@^3.1.0
- Removeduuid@3.4.0(transitive)