fluorine-lib
Version:
Reactive state and side effect management for React using a single stream of actions
49 lines (32 loc) • 2.46 kB
JavaScript
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; };
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(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) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import React, { Component } from 'react';
import wrapActions from '../util/wrapActions';
export default function connectActions(actions) {
var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'actions';
var wrapRecursively = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
return function (Child) {
var _class, _temp;
return _temp = _class = function (_Component) {
_inherits(Connector, _Component);
function Connector(props) {
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, Connector);
var _this = _possibleConstructorReturn(this, _Component.call(this, props, context));
var observer = context.observer;
_this.actions = wrapActions(observer, actions, wrapRecursively);
return _this;
}
Connector.prototype.render = function render() {
var _extends2;
var observer = this.context.observer;
return React.createElement(Child, _extends({}, this.props, (_extends2 = {}, _extends2[prop] = this.actions, _extends2.observer = observer, _extends2)));
};
return Connector;
}(Component), _class.contextTypes = {
observer: React.PropTypes.object
}, _temp;
};
}