UNPKG

react-component-managers

Version:
39 lines (29 loc) 2.17 kB
"use strict"; exports.__esModule = true; exports.mixin = mixin; exports.default = mixIntoClass; function _extends() { _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; }; return _extends.apply(this, arguments); } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function mixin(componentClass, _ref) { var propTypes = _ref.propTypes, contextTypes = _ref.contextTypes, childContextTypes = _ref.childContextTypes, getChildContext = _ref.getChildContext, protoSpec = _objectWithoutProperties(_ref, ["propTypes", "contextTypes", "childContextTypes", "getChildContext"]); if (propTypes) componentClass.propTypes = _extends({}, componentClass.propTypes, propTypes); if (contextTypes) componentClass.contextTypes = _extends({}, componentClass.contextTypes, contextTypes); if (childContextTypes) componentClass.childContextTypes = _extends({}, componentClass.childContextTypes, childContextTypes); if (getChildContext) { var baseGCContext = componentClass.prototype.getChildContext; componentClass.prototype.getChildContext = function $getChildContext() { return _extends({}, baseGCContext && baseGCContext.call(this), getChildContext.call(this)); }; } _extends(componentClass.prototype, protoSpec); return componentClass; } function mixIntoClass(spec) { return function (componentClass) { return mixin(componentClass, spec); }; }