From c58161806d23f79ff26d13e4e364ca2fe41fd5fe Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Wed, 26 Oct 2016 16:49:35 -0400 Subject: [PATCH] Do "npm run build" This lets the package be installed via NPM / Yarn directly off of GitHub and be up to date. --- lib/Gateway.js | 6 +++--- lib/GatewayDest.js | 16 ++++++---------- lib/GatewayRegistry.js | 20 +++++++++++--------- lib/index.js | 34 ++++++++++++++++++++++------------ 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/lib/Gateway.js b/lib/Gateway.js index fd3a96d..7168e54 100644 --- a/lib/Gateway.js +++ b/lib/Gateway.js @@ -35,16 +35,15 @@ var Gateway = function (_React$Component) { }; Gateway.prototype.componentWillReceiveProps = function componentWillReceiveProps(props) { - this.gatewayRegistry.clearChild(this.props.into); this.renderIntoGatewayNode(props); }; Gateway.prototype.componentWillUnmount = function componentWillUnmount() { - this.gatewayRegistry.removeChild(this.props.into); + this.gatewayRegistry.removeChild(this.props.into, this.props.id); }; Gateway.prototype.renderIntoGatewayNode = function renderIntoGatewayNode(props) { - this.gatewayRegistry.addChild(this.props.into, props.children); + this.gatewayRegistry.addChild(props.into, props.children, props.id); }; Gateway.prototype.render = function render() { @@ -59,6 +58,7 @@ Gateway.contextTypes = { }; Gateway.propTypes = { into: _react2.default.PropTypes.string.isRequired, + id: _react2.default.PropTypes.string.isRequired, children: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.element, _react2.default.PropTypes.string]) }; exports.default = Gateway; \ No newline at end of file diff --git a/lib/GatewayDest.js b/lib/GatewayDest.js index f0b72c4..b63698e 100644 --- a/lib/GatewayDest.js +++ b/lib/GatewayDest.js @@ -10,8 +10,6 @@ var _GatewayRegistry = require('./GatewayRegistry'); var _GatewayRegistry2 = _interopRequireDefault(_GatewayRegistry); -var _reactPropTypes = require('react-prop-types'); - function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } @@ -31,7 +29,7 @@ var GatewayDest = function (_React$Component) { var _this = _possibleConstructorReturn(this, _React$Component.call(this, props, context)); _this.state = { - child: null + children: null // array of children }; _this.gatewayRegistry = context.gatewayRegistry; @@ -47,14 +45,13 @@ var GatewayDest = function (_React$Component) { }; GatewayDest.prototype.render = function render() { - var _props = this.props; - var component = _props.component; - var tagName = _props.tagName; - - var attrs = _objectWithoutProperties(_props, ['component', 'tagName']); + var _props = this.props, + component = _props.component, + tagName = _props.tagName, + attrs = _objectWithoutProperties(_props, ['component', 'tagName']); delete attrs.name; - return _react2.default.createElement(component || tagName || 'div', attrs, this.state.child); + return _react2.default.createElement(component || 'div', attrs, this.state.children); // this is now an array of children }; return GatewayDest; @@ -65,7 +62,6 @@ GatewayDest.contextTypes = { }; GatewayDest.propTypes = { name: _react2.default.PropTypes.string.isRequired, - tagName: (0, _reactPropTypes.deprecated)(_react2.default.PropTypes.string, 'Use "component" instead.'), component: _react2.default.PropTypes.oneOfType([_react2.default.PropTypes.string, _react2.default.PropTypes.func]) }; exports.default = GatewayDest; \ No newline at end of file diff --git a/lib/GatewayRegistry.js b/lib/GatewayRegistry.js index 2a6d6e3..a0b5584 100644 --- a/lib/GatewayRegistry.js +++ b/lib/GatewayRegistry.js @@ -2,6 +2,8 @@ exports.__esModule = true; +var _lodash = require('lodash'); + function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var GatewayRegistry = function () { @@ -18,7 +20,7 @@ var GatewayRegistry = function () { } this._containers[name].setState({ - child: this._children[name] + children: (0, _lodash.toArray)(this._children[name]) }); }; @@ -31,20 +33,20 @@ var GatewayRegistry = function () { this._containers[name] = null; }; - GatewayRegistry.prototype.addChild = function addChild(name, child) { - if (this._children[name]) { - console.warn('Only a single Gateway can be rendered at a time into a GatewayDest.' + ('You rendered multiple into "' + name + '"')); + GatewayRegistry.prototype.addChild = function addChild(name, child, gatewayId) { + if (!this._children[name]) { + this._children[name] = {}; } - this._children[name] = child; + this._children[name][gatewayId] = child; this._renderContainer(name); }; - GatewayRegistry.prototype.clearChild = function clearChild(name) { - this._children[name] = null; + GatewayRegistry.prototype.clearChild = function clearChild(name, gatewayId) { + delete this._children[name][gatewayId]; }; - GatewayRegistry.prototype.removeChild = function removeChild(name) { - this.clearChild(name); + GatewayRegistry.prototype.removeChild = function removeChild(name, gatewayId) { + this.clearChild(name, gatewayId); this._renderContainer(name); }; diff --git a/lib/index.js b/lib/index.js index 3948ba4..01caa7e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,22 +1,32 @@ 'use strict'; exports.__esModule = true; -exports.GatewayProvider = exports.GatewayDest = exports.Gateway = undefined; -var _Gateway2 = require('./Gateway'); +var _Gateway = require('./Gateway'); -var _Gateway3 = _interopRequireDefault(_Gateway2); +Object.defineProperty(exports, 'Gateway', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_Gateway).default; + } +}); -var _GatewayDest2 = require('./GatewayDest'); +var _GatewayDest = require('./GatewayDest'); -var _GatewayDest3 = _interopRequireDefault(_GatewayDest2); +Object.defineProperty(exports, 'GatewayDest', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_GatewayDest).default; + } +}); -var _GatewayProvider2 = require('./GatewayProvider'); +var _GatewayProvider = require('./GatewayProvider'); -var _GatewayProvider3 = _interopRequireDefault(_GatewayProvider2); +Object.defineProperty(exports, 'GatewayProvider', { + enumerable: true, + get: function get() { + return _interopRequireDefault(_GatewayProvider).default; + } +}); -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -exports.Gateway = _Gateway3.default; -exports.GatewayDest = _GatewayDest3.default; -exports.GatewayProvider = _GatewayProvider3.default; \ No newline at end of file +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } \ No newline at end of file