react-refect
Advanced tools
Comparing version
@@ -11,2 +11,4 @@ "use strict"; | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics")); | ||
@@ -30,2 +32,4 @@ | ||
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -51,6 +55,6 @@ | ||
var storeShape = _react.PropTypes.shape({ | ||
subscribe: _react.PropTypes.func.isRequired, | ||
dispatch: _react.PropTypes.func.isRequired, | ||
getState: _react.PropTypes.func.isRequired | ||
var storeShape = _propTypes.default.shape({ | ||
subscribe: _propTypes.default.func.isRequired, | ||
dispatch: _propTypes.default.func.isRequired, | ||
getState: _propTypes.default.func.isRequired | ||
}); | ||
@@ -95,31 +99,52 @@ | ||
var RefectComponent = | ||
var ContextWrapper = | ||
/*#__PURE__*/ | ||
function (_Component) { | ||
_inherits(RefectComponent, _Component); | ||
_inherits(ContextWrapper, _Component); | ||
function RefectComponent(props, context) { | ||
var _this; | ||
function ContextWrapper() { | ||
_classCallCheck(this, ContextWrapper); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ContextWrapper).apply(this, arguments)); | ||
} | ||
_createClass(ContextWrapper, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this = this; | ||
return _react.default.createElement(_reactRedux.ReactReduxContext.Consumer, null, function (context) { | ||
return _react.default.createElement(RefectComponent, _extends({}, _this.props, { | ||
context: context | ||
})); | ||
}); | ||
} | ||
}]); | ||
return ContextWrapper; | ||
}(_react.Component); | ||
var RefectComponent = | ||
/*#__PURE__*/ | ||
function (_Component2) { | ||
_inherits(RefectComponent, _Component2); | ||
function RefectComponent(props) { | ||
var _this2; | ||
_classCallCheck(this, RefectComponent); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(RefectComponent).call(this, props, context)); | ||
_this.store = context.store; | ||
_this2 = _possibleConstructorReturn(this, _getPrototypeOf(RefectComponent).call(this, props)); | ||
var context = props.context; | ||
var parentNamespace = context.namespace || ''; | ||
_this.state = { | ||
_this2.store = context.store; | ||
_this2.state = { | ||
storeState: initialState, | ||
storeAllState: _this.store.getState() | ||
storeAllState: _this2.store.getState() | ||
}; | ||
_this.namespace = getNamespace(parentNamespace, props.namespace); | ||
return _this; | ||
_this2.namespace = getNamespace(parentNamespace, props.namespace); | ||
return _this2; | ||
} | ||
_createClass(RefectComponent, [{ | ||
key: "getChildContext", | ||
value: function getChildContext() { | ||
return { | ||
namespace: this.namespace | ||
}; | ||
} | ||
}, { | ||
key: "componentWillMount", | ||
@@ -141,10 +166,10 @@ value: function componentWillMount() { | ||
value: function componentDidMount() { | ||
var _this2 = this; | ||
var _this3 = this; | ||
this.unSubscribe = this.store.subscribe(function () { | ||
var storeAllState = _this2.store.getState(); | ||
var storeAllState = _this3.store.getState(); | ||
var storeState = (0, _utils.get)(storeAllState, _this2.namespace); | ||
var storeState = (0, _utils.get)(storeAllState, _this3.namespace); | ||
_this2.setState({ | ||
_this3.setState({ | ||
storeState: storeState, | ||
@@ -195,13 +220,4 @@ storeAllState: storeAllState | ||
_defineProperty(RefectComponent, "contextTypes", { | ||
store: storeShape, | ||
namespace: _react.PropTypes.string | ||
}); | ||
_defineProperty(RefectComponent, "childContextTypes", { | ||
namespace: _react.PropTypes.string | ||
}); | ||
_defineProperty(RefectComponent, "propTypes", { | ||
namespace: _react.PropTypes.string | ||
namespace: _propTypes.default.string | ||
}); | ||
@@ -218,4 +234,4 @@ | ||
var wrappedComponentName = view.displayName || view.name || 'Component'; | ||
RefectComponent.displayName = "Refect(".concat(wrappedComponentName, ")"); | ||
return (0, _hoistNonReactStatics.default)(RefectComponent, view); | ||
ContextWrapper.displayName = "Refect(".concat(wrappedComponentName, ")"); | ||
return (0, _hoistNonReactStatics.default)(ContextWrapper, view); | ||
} | ||
@@ -222,0 +238,0 @@ |
{ | ||
"name": "react-refect", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -28,5 +28,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"refect": "^1.0.0", | ||
"hoist-non-react-statics": "^1.2.0", | ||
"react-redux": "^6.0.0" | ||
"prop-types": "^15.6.2", | ||
"react-redux": "^6.0.0", | ||
"refect": "^1.0.0" | ||
}, | ||
@@ -33,0 +34,0 @@ "peerDependencies": { |
@@ -1,2 +0,3 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import hoistStatics from 'hoist-non-react-statics'; | ||
@@ -6,2 +7,3 @@ import { Provider } from 'react-redux'; | ||
import { get, is } from 'refect/utils'; | ||
import { ReactReduxContext } from 'react-redux'; | ||
@@ -47,12 +49,15 @@ const storeShape = PropTypes.shape({ | ||
class ContextWrapper extends Component { | ||
render() { | ||
return ( | ||
<ReactReduxContext.Consumer> | ||
{(context) => { | ||
return <RefectComponent {...this.props} context={context}/> | ||
}} | ||
</ReactReduxContext.Consumer> | ||
) | ||
} | ||
} | ||
class RefectComponent extends Component { | ||
static contextTypes = { | ||
store: storeShape, | ||
namespace: PropTypes.string, | ||
}; | ||
static childContextTypes = { | ||
namespace: PropTypes.string, | ||
}; | ||
static propTypes = { | ||
@@ -71,8 +76,8 @@ namespace: PropTypes.string, | ||
constructor(props, context) { | ||
super(props, context); | ||
constructor(props) { | ||
super(props); | ||
const context = props.context; | ||
const parentNamespace = context.namespace || ''; | ||
this.store = context.store; | ||
const parentNamespace = context.namespace || ''; | ||
this.state = { | ||
@@ -86,8 +91,2 @@ storeState: initialState, | ||
getChildContext() { | ||
return { | ||
namespace: this.namespace, | ||
}; | ||
} | ||
componentWillMount() { | ||
@@ -155,5 +154,5 @@ this.actions = configureRefect({ | ||
RefectComponent.displayName = `Refect(${wrappedComponentName})`; | ||
ContextWrapper.displayName = `Refect(${wrappedComponentName})`; | ||
return hoistStatics(RefectComponent, view); | ||
return hoistStatics(ContextWrapper, view); | ||
} | ||
@@ -160,0 +159,0 @@ |
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
18448
5.22%348
3.88%0
-100%5
25%+ Added