UNPKG

react-af

Version:

Code using modern React features today! It does for React what Babel does for JavaScript.

163 lines (129 loc) 5.12 kB
import createReactContext from 'create-react-context'; import React from 'react'; /* eslint-disable import/prefer-default-export */ var setKeyOnTarget = function setKeyOnTarget(setFn) { return function (target, key) { // eslint-disable-next-line no-param-reassign target[key] = setFn(key); return target; }; }; var objectWithoutProperties = function objectWithoutProperties(obj, keysArr) { // eslint-disable-next-line no-param-reassign var keys = keysArr.reduce(setKeyOnTarget(function (key) { return key; }), {}); return Object.keys(obj).filter(function (key) { return !keys[key]; }).reduce(setKeyOnTarget(function (key) { return obj[key]; }), {}); }; var classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; 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; }; 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) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }; var possibleConstructorReturn = function (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; }; /* eslint-disable react/no-multi-comp */ var EmulatedFragment = 'div'; function getDerivedStateFromProps(instance, props, prevState) { var state = instance.constructor.getDerivedStateFromProps(props, prevState); if (state) { instance.setState(state); } } function componentWillMount() { getDerivedStateFromProps(this, this.props, this.state); } // eslint-disable-next-line no-underscore-dangle componentWillMount.__suppressDeprecationWarning = true; function componentWillReceiveProps(nextProps) { getDerivedStateFromProps(this, nextProps, this.state); } // eslint-disable-next-line no-underscore-dangle componentWillReceiveProps.__suppressDeprecationWarning = true; function setMethodSafe(instance, method, fn) { if (instance[method]) { throw new Error('[' + instance.constructor.name + '] ' + method + ' has been deprecated'); } // eslint-disable-next-line no-param-reassign instance[method] = fn; } function enhanceComponent(instance) { if (instance.constructor.getDerivedStateFromProps) { setMethodSafe(instance, 'componentWillMount', componentWillMount); setMethodSafe(instance, 'componentWillReceiveProps', componentWillReceiveProps); } } var createReactAF = function createReactAF(React$$1) { return React$$1.StrictMode // 16.3 and above? ? React$$1 // Return as-is. : _extends({}, objectWithoutProperties(React$$1, ['PropTypes', 'createClass']), { // So 15.x doesn't warn. Component: function (_React$Component) { inherits(ReactAFComponent, _React$Component); function ReactAFComponent() { var _ref; classCallCheck(this, ReactAFComponent); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _this = possibleConstructorReturn(this, (_ref = ReactAFComponent.__proto__ || Object.getPrototypeOf(ReactAFComponent)).call.apply(_ref, [this].concat(args))); enhanceComponent(_this); return _this; } return ReactAFComponent; }(React$$1.Component), PureComponent: function (_React$PureComponent) { inherits(ReactAFPureComponent, _React$PureComponent); function ReactAFPureComponent() { var _ref2; classCallCheck(this, ReactAFPureComponent); for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } var _this2 = possibleConstructorReturn(this, (_ref2 = ReactAFPureComponent.__proto__ || Object.getPrototypeOf(ReactAFPureComponent)).call.apply(_ref2, [this].concat(args))); enhanceComponent(_this2); return _this2; } return ReactAFPureComponent; }(React$$1.PureComponent), isGetDerivedStateFromPropsEmulated: true, Fragment: React$$1.Fragment || EmulatedFragment, isFragmentEmulated: !React$$1.Fragment, createContext: React$$1.createContext || createReactContext, isCreateContextEmulated: !React$$1.createContext }); }; var ReactAF = createReactAF(React); module.exports = ReactAF.default ? ReactAF.default : ReactAF;