'use strict';
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj['default'] : obj; };
var _objectWithoutProperties = function (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; };
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } };
var _inherits = function (subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };
var _React = require('react/addons');
var React = _interopRequire(_React);
var _instanceMethods$staticProperties = require('./reactComponentMethods');
var _assign = require('object-assign');
var assign = _interopRequire(_assign);
var FluxComponent = (function (_React$Component) {
function FluxComponent(props, context) {
_classCallCheck(this, FluxComponent);
_React$Component.call(this, props, context);
this.initialize();
this.state = this.connectToStores(props.connectToStores, props.stateGetter);
this.wrapChild = this.wrapChild.bind(this);
}
_inherits(FluxComponent, _React$Component);
FluxComponent.prototype.wrapChild = function wrapChild(child) {
return React.addons.cloneWithProps(child, this.getChildProps());
};
FluxComponent.prototype.getChildProps = function getChildProps() {
var _props = this.props;
var children = _props.children;
var render = _props.render;
var connectToStores = _props.connectToStores;
var stateGetter = _props.stateGetter;
var flux = _props.flux;
var extraProps = _objectWithoutProperties(_props, ['children', 'render', 'connectToStores', 'stateGetter', 'flux']);
return assign({ flux: this.getFlux() },
this.state, extraProps);
};
FluxComponent.prototype.render = (function (_render) {
function render() {
return _render.apply(this, arguments);
}
render.toString = function () {
return render.toString();
};
return render;
})(function () {
var _props2 = this.props;
var children = _props2.children;
var render = _props2.render;
if (typeof render === 'function') {
return render(this.getChildProps(), this.getFlux());
}
if (!children) return null;
if (!Array.isArray(children)) {
var child = children;
return this.wrapChild(child);
} else {
return React.createElement(
'span',
null,
React.Children.map(children, this.wrapChild)
);
}
});
return FluxComponent;
})(React.Component);
assign(FluxComponent.prototype, _instanceMethods$staticProperties.instanceMethods);
assign(FluxComponent, _instanceMethods$staticProperties.staticProperties);
module.exports = FluxComponent;