@reach/component-component
Advanced tools
Comparing version 0.1.3 to 0.3.0-alpha.0
114
es/index.js
@@ -1,8 +0,8 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
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 _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
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; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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; } | ||
function _objectWithoutPropertiesLoose(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]; } return target; } | ||
@@ -23,3 +23,3 @@ import React from "react"; | ||
render = props.render, | ||
rest = _objectWithoutProperties(props, ["initialState", "getInitialState", "refs", "getRefs", "didMount", "didUpdate", "willUnmount", "getSnapshotBeforeUpdate", "shouldUpdate", "render"]); | ||
rest = _objectWithoutPropertiesLoose(props, ["initialState", "getInitialState", "refs", "getRefs", "didMount", "didUpdate", "willUnmount", "getSnapshotBeforeUpdate", "shouldUpdate", "render"]); | ||
@@ -29,18 +29,38 @@ return rest; | ||
var Component = function (_React$Component) { | ||
_inherits(Component, _React$Component); | ||
var Component = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(Component, _React$Component); | ||
function Component() { | ||
var _temp, _this, _ret; | ||
var _this; | ||
_classCallCheck(this, Component); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
_args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _initialiseProps.call(_this), _temp), _possibleConstructorReturn(_this, _ret); | ||
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this; | ||
_defineProperty(_assertThisInitialized(_this), "state", _this.props.initialState || _this.props.getInitialState(_this.props)); | ||
_defineProperty(_assertThisInitialized(_this), "_refs", _this.props.refs || _this.props.getRefs(_this.getArgs())); | ||
_defineProperty(_assertThisInitialized(_this), "_setState", function () { | ||
var _this2; | ||
return (_this2 = _this).setState.apply(_this2, arguments); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "_forceUpdate", function () { | ||
var _this3; | ||
return (_this3 = _this).forceUpdate.apply(_this3, arguments); | ||
}); | ||
return _this; | ||
} | ||
Component.prototype.getArgs = function getArgs() { | ||
var _proto = Component.prototype; | ||
_proto.getArgs = function getArgs() { | ||
var state = this.state, | ||
@@ -51,3 +71,2 @@ props = this.props, | ||
refs = this._refs; | ||
return { | ||
@@ -62,7 +81,7 @@ state: state, | ||
Component.prototype.componentDidMount = function componentDidMount() { | ||
_proto.componentDidMount = function componentDidMount() { | ||
if (this.props.didMount) this.props.didMount(this.getArgs()); | ||
}; | ||
Component.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) { | ||
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) { | ||
if (this.props.shouldUpdate) return this.props.shouldUpdate({ | ||
@@ -76,3 +95,3 @@ props: this.props, | ||
Component.prototype.componentWillUnmount = function componentWillUnmount() { | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
if (this.props.willUnmount) this.props.willUnmount({ | ||
@@ -85,3 +104,3 @@ state: this.state, | ||
Component.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState, snapshot) { | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState, snapshot) { | ||
if (this.props.didUpdate) this.props.didUpdate(Object.assign(this.getArgs(), { | ||
@@ -93,3 +112,3 @@ prevProps: cleanProps(prevProps), | ||
Component.prototype.getSnapshotBeforeUpdate = function getSnapshotBeforeUpdate(prevProps, prevState) { | ||
_proto.getSnapshotBeforeUpdate = function getSnapshotBeforeUpdate(prevProps, prevState) { | ||
if (this.props.getSnapshotBeforeUpdate) { | ||
@@ -105,7 +124,6 @@ return this.props.getSnapshotBeforeUpdate(Object.assign(this.getArgs(), { | ||
Component.prototype.render = function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
render = _props.render; | ||
_proto.render = function render() { | ||
var _this$props = this.props, | ||
children = _this$props.children, | ||
render = _this$props.render; | ||
return render ? render(this.getArgs()) : typeof children === "function" ? children(this.getArgs()) : children || null; | ||
@@ -117,3 +135,3 @@ }; | ||
Component.defaultProps = { | ||
_defineProperty(Component, "defaultProps", { | ||
getInitialState: function getInitialState() {}, | ||
@@ -123,34 +141,20 @@ getRefs: function getRefs() { | ||
} | ||
}; | ||
}); | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.state = this.props.initialState || this.props.getInitialState(this.props); | ||
this._refs = this.props.refs || this.props.getRefs(this.getArgs()); | ||
this._setState = function () { | ||
return _this2.setState.apply(_this2, arguments); | ||
if (process.env.NODE_ENV !== "production") { | ||
Component.propTypes = { | ||
initialState: object, | ||
getInitialState: func, | ||
refs: object, | ||
getRefs: func, | ||
didMount: func, | ||
didUpdate: func, | ||
willUnmount: func, | ||
getSnapshotBeforeUpdate: func, | ||
shouldUpdate: func, | ||
render: func, | ||
children: oneOfType([func, node]) | ||
}; | ||
} | ||
this._forceUpdate = function () { | ||
return _this2.forceUpdate.apply(_this2, arguments); | ||
}; | ||
}; | ||
process.env.NODE_ENV !== "production" ? Component.propTypes = { | ||
initialState: object, | ||
getInitialState: func, | ||
refs: object, | ||
getRefs: func, | ||
didMount: func, | ||
didUpdate: func, | ||
willUnmount: func, | ||
getSnapshotBeforeUpdate: func, | ||
shouldUpdate: func, | ||
render: func, | ||
children: oneOfType([func, node]) | ||
} : void 0; | ||
export default Component; |
124
index.js
"use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = void 0; | ||
var _react = require("react"); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _react2 = _interopRequireDefault(_react); | ||
var _propTypes = require("prop-types"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
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 _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } | ||
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; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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; } | ||
function _objectWithoutPropertiesLoose(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]; } return target; } | ||
@@ -32,3 +31,3 @@ var cleanProps = function cleanProps(props) { | ||
render = props.render, | ||
rest = _objectWithoutProperties(props, ["initialState", "getInitialState", "refs", "getRefs", "didMount", "didUpdate", "willUnmount", "getSnapshotBeforeUpdate", "shouldUpdate", "render"]); | ||
rest = _objectWithoutPropertiesLoose(props, ["initialState", "getInitialState", "refs", "getRefs", "didMount", "didUpdate", "willUnmount", "getSnapshotBeforeUpdate", "shouldUpdate", "render"]); | ||
@@ -38,18 +37,38 @@ return rest; | ||
var Component = function (_React$Component) { | ||
_inherits(Component, _React$Component); | ||
var Component = | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(Component, _React$Component); | ||
function Component() { | ||
var _temp, _this, _ret; | ||
var _this; | ||
_classCallCheck(this, Component); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
_args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _initialiseProps.call(_this), _temp), _possibleConstructorReturn(_this, _ret); | ||
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this; | ||
_defineProperty(_assertThisInitialized(_this), "state", _this.props.initialState || _this.props.getInitialState(_this.props)); | ||
_defineProperty(_assertThisInitialized(_this), "_refs", _this.props.refs || _this.props.getRefs(_this.getArgs())); | ||
_defineProperty(_assertThisInitialized(_this), "_setState", function () { | ||
var _this2; | ||
return (_this2 = _this).setState.apply(_this2, arguments); | ||
}); | ||
_defineProperty(_assertThisInitialized(_this), "_forceUpdate", function () { | ||
var _this3; | ||
return (_this3 = _this).forceUpdate.apply(_this3, arguments); | ||
}); | ||
return _this; | ||
} | ||
Component.prototype.getArgs = function getArgs() { | ||
var _proto = Component.prototype; | ||
_proto.getArgs = function getArgs() { | ||
var state = this.state, | ||
@@ -60,3 +79,2 @@ props = this.props, | ||
refs = this._refs; | ||
return { | ||
@@ -71,7 +89,7 @@ state: state, | ||
Component.prototype.componentDidMount = function componentDidMount() { | ||
_proto.componentDidMount = function componentDidMount() { | ||
if (this.props.didMount) this.props.didMount(this.getArgs()); | ||
}; | ||
Component.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) { | ||
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) { | ||
if (this.props.shouldUpdate) return this.props.shouldUpdate({ | ||
@@ -85,3 +103,3 @@ props: this.props, | ||
Component.prototype.componentWillUnmount = function componentWillUnmount() { | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
if (this.props.willUnmount) this.props.willUnmount({ | ||
@@ -94,3 +112,3 @@ state: this.state, | ||
Component.prototype.componentDidUpdate = function componentDidUpdate(prevProps, prevState, snapshot) { | ||
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState, snapshot) { | ||
if (this.props.didUpdate) this.props.didUpdate(Object.assign(this.getArgs(), { | ||
@@ -102,3 +120,3 @@ prevProps: cleanProps(prevProps), | ||
Component.prototype.getSnapshotBeforeUpdate = function getSnapshotBeforeUpdate(prevProps, prevState) { | ||
_proto.getSnapshotBeforeUpdate = function getSnapshotBeforeUpdate(prevProps, prevState) { | ||
if (this.props.getSnapshotBeforeUpdate) { | ||
@@ -114,7 +132,6 @@ return this.props.getSnapshotBeforeUpdate(Object.assign(this.getArgs(), { | ||
Component.prototype.render = function render() { | ||
var _props = this.props, | ||
children = _props.children, | ||
render = _props.render; | ||
_proto.render = function render() { | ||
var _this$props = this.props, | ||
children = _this$props.children, | ||
render = _this$props.render; | ||
return render ? render(this.getArgs()) : typeof children === "function" ? children(this.getArgs()) : children || null; | ||
@@ -124,5 +141,5 @@ }; | ||
return Component; | ||
}(_react2.default.Component); | ||
}(_react["default"].Component); | ||
Component.defaultProps = { | ||
_defineProperty(Component, "defaultProps", { | ||
getInitialState: function getInitialState() {}, | ||
@@ -132,32 +149,21 @@ getRefs: function getRefs() { | ||
} | ||
}; | ||
}); | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.state = this.props.initialState || this.props.getInitialState(this.props); | ||
this._refs = this.props.refs || this.props.getRefs(this.getArgs()); | ||
this._setState = function () { | ||
return _this2.setState.apply(_this2, arguments); | ||
if (process.env.NODE_ENV !== "production") { | ||
Component.propTypes = { | ||
initialState: _propTypes.object, | ||
getInitialState: _propTypes.func, | ||
refs: _propTypes.object, | ||
getRefs: _propTypes.func, | ||
didMount: _propTypes.func, | ||
didUpdate: _propTypes.func, | ||
willUnmount: _propTypes.func, | ||
getSnapshotBeforeUpdate: _propTypes.func, | ||
shouldUpdate: _propTypes.func, | ||
render: _propTypes.func, | ||
children: (0, _propTypes.oneOfType)([_propTypes.func, _propTypes.node]) | ||
}; | ||
} | ||
this._forceUpdate = function () { | ||
return _this2.forceUpdate.apply(_this2, arguments); | ||
}; | ||
}; | ||
process.env.NODE_ENV !== "production" ? Component.propTypes = { | ||
initialState: _propTypes.object, | ||
getInitialState: _propTypes.func, | ||
refs: _propTypes.object, | ||
getRefs: _propTypes.func, | ||
didMount: _propTypes.func, | ||
didUpdate: _propTypes.func, | ||
willUnmount: _propTypes.func, | ||
getSnapshotBeforeUpdate: _propTypes.func, | ||
shouldUpdate: _propTypes.func, | ||
render: _propTypes.func, | ||
children: (0, _propTypes.oneOfType)([_propTypes.func, _propTypes.node]) | ||
} : void 0; | ||
exports.default = Component; | ||
var _default = Component; | ||
exports["default"] = _default; |
{ | ||
"name": "@reach/component-component", | ||
"version": "0.1.3", | ||
"version": "0.3.0-alpha.0", | ||
"description": "Declarative React Component Definitions", | ||
@@ -8,3 +8,2 @@ "main": "index.js", | ||
"scripts": { | ||
"test": "jest", | ||
"build": "node ../../shared/build-package", | ||
@@ -15,4 +14,6 @@ "lint": "eslint . --max-warnings=0" | ||
"license": "MIT", | ||
"dependencies": { | ||
"prop-types": "^15.7.2" | ||
}, | ||
"peerDependencies": { | ||
"prop-types": "^15.6.2", | ||
"react": "^16.4.0", | ||
@@ -22,10 +23,5 @@ "react-dom": "^16.4.0" | ||
"devDependencies": { | ||
"jest": "^23.4.2", | ||
"react": "^16.4.1", | ||
"react-test-renderer": "^16.4.1" | ||
"react": "^16.8.0", | ||
"react-test-renderer": "^16.8.0" | ||
}, | ||
"jest": { | ||
"testRegex": ".+\\.test\\.js$", | ||
"testURL": "http://localhost" | ||
}, | ||
"files": [ | ||
@@ -37,3 +33,4 @@ "es", | ||
"styles.css" | ||
] | ||
], | ||
"gitHead": "3234e9cf2a55f51c31ac5a7d883d34d6be6f033d" | ||
} |
@@ -22,16 +22,2 @@ import React from "react"; | ||
class Component extends React.Component { | ||
static propTypes = { | ||
initialState: object, | ||
getInitialState: func, | ||
refs: object, | ||
getRefs: func, | ||
didMount: func, | ||
didUpdate: func, | ||
willUnmount: func, | ||
getSnapshotBeforeUpdate: func, | ||
shouldUpdate: func, | ||
render: func, | ||
children: oneOfType([func, node]) | ||
}; | ||
static defaultProps = { | ||
@@ -117,7 +103,23 @@ getInitialState: () => {}, | ||
: typeof children === "function" | ||
? children(this.getArgs()) | ||
: children || null; | ||
? children(this.getArgs()) | ||
: children || null; | ||
} | ||
} | ||
if (__DEV__) { | ||
Component.propTypes = { | ||
initialState: object, | ||
getInitialState: func, | ||
refs: object, | ||
getRefs: func, | ||
didMount: func, | ||
didUpdate: func, | ||
willUnmount: func, | ||
getSnapshotBeforeUpdate: func, | ||
shouldUpdate: func, | ||
render: func, | ||
children: oneOfType([func, node]) | ||
}; | ||
} | ||
export default Component; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27469
2
8
702
1
+ Addedprop-types@^15.7.2