Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
16 changes: 6 additions & 10 deletions lib/GatewayDest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
20 changes: 11 additions & 9 deletions lib/GatewayRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -18,7 +20,7 @@ var GatewayRegistry = function () {
}

this._containers[name].setState({
child: this._children[name]
children: (0, _lodash.toArray)(this._children[name])
});
};

Expand All @@ -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);
};

Expand Down
34 changes: 22 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }