react-esc-resolver
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -12,11 +12,15 @@ 'use strict'; | ||
var capitalize = function capitalize(word) { | ||
var canUseDom = (function () { | ||
return typeof window !== 'undefined'; | ||
}); | ||
var capitalize = (function (word) { | ||
return word.replace(/^./, function (letter) { | ||
return letter.toUpperCase(); | ||
}); | ||
}; | ||
}); | ||
var hasOwnProperty = function hasOwnProperty(object, prop) { | ||
var hasOwnProperty = (function (object, prop) { | ||
return Object.prototype.hasOwnProperty.call(object, prop); | ||
}; | ||
}); | ||
@@ -144,3 +148,3 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { | ||
if (cache || isServer) { | ||
if (cache || !canUseDom()) { | ||
if (hasOwnProperty(props, resolve)) { | ||
@@ -457,16 +461,2 @@ return props[resolve]; | ||
var canUseDom = (function () { | ||
return typeof window !== 'undefined'; | ||
}); | ||
var capitalize$1 = (function (word) { | ||
return word.replace(/^./, function (letter) { | ||
return letter.toUpperCase(); | ||
}); | ||
}); | ||
var hasOwnProperty$1 = (function (object, prop) { | ||
return Object.prototype.hasOwnProperty.call(object, prop); | ||
}); | ||
var client = (function (prop, Loader) { | ||
@@ -477,3 +467,3 @@ var promise = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var loadProps = typeof prop === 'string' ? [prop] : prop; | ||
var names = loadProps.map(capitalize$1).join(''); | ||
var names = loadProps.map(capitalize).join(''); | ||
@@ -501,3 +491,3 @@ return function (Component) { | ||
loadProps.forEach(function (prop) { | ||
if (!hasOwnProperty$1(_this.props, prop) || !_this.props[prop]) { | ||
if (!hasOwnProperty(_this.props, prop) || !_this.props[prop]) { | ||
loaded = false; | ||
@@ -512,3 +502,3 @@ } | ||
_this.state = { | ||
bypass: !canUseDom() && !promise || "development" === 'test', | ||
bypass: !canUseDom() && !promise || process.env.NODE_ENV === 'test', | ||
loaded: _this.isLoaded(props) | ||
@@ -539,6 +529,6 @@ }; | ||
return React.createElement( | ||
'div', | ||
React.Fragment, | ||
null, | ||
React.createElement(Loader, null), | ||
React.createElement( | ||
!promise && React.createElement( | ||
'div', | ||
@@ -545,0 +535,0 @@ { style: { display: 'none' } }, |
@@ -1,2 +0,2 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=_interopDefault(require("react")),PropTypes=_interopDefault(require("prop-types")),ReactDOM=_interopDefault(require("react-dom")),server=require("react-dom/server"),capitalize=function(e){return e.replace(/^./,function(e){return e.toUpperCase()})},hasOwnProperty=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),defineProperty=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},HAS_RESOLVED="ReactResolver.HAS_RESOLVED",IS_CLIENT="ReactResolver.IS_CLIENT",Resolver=function(e){function t(e,n){classCallCheck(this,t);var r=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.unMounted=!0,r[HAS_RESOLVED]=!1,r[IS_CLIENT]=!1,r.state=r.computeState(r.props,{pending:{},resolved:{}}),r.isPending(r.state)?(r.resolve(r.state),r[HAS_RESOLVED]=!1):r[HAS_RESOLVED]=!0,r}return inherits(t,e),createClass(t,[{key:"cached",value:function(e){var t=this.props,n=t.props;if(t.cache||isServer){if(hasOwnProperty(n,e))return n[e];if(this.context.resolver)return this.context.resolver.cached(e)}return null}},{key:"componentWillMount",value:function(){this.unMounted=!1}},{key:"componentDidMount",value:function(){this[IS_CLIENT]=!0}},{key:"componentWillUnmount",value:function(){this.unMounted=!0}},{key:"componentWillReceiveProps",value:function(e){var t=this.computeState(e,this.state),n={pending:t.pending,resolved:t.resolved};this.setAtomicState(n)}},{key:"computeState",value:function(e,t){var n=this,r=e.resolve,o=t;return Object.keys(r).forEach(function(e){var s=n.cached(e);hasOwnProperty(t.resolved,e)||hasOwnProperty(t.pending,e)||n.isValidCache(s)?s&&(o.resolved[e]=!0):o.pending[e]=r[e]}),o}},{key:"getChildContext",value:function(){return{resolver:this}}},{key:"isValidCache",value:function(e){return null!==e&&void 0!==e&&("object"!==(void 0===e?"undefined":_typeof(e))||Object.keys(e).length>0)&&(!Array.isArray(e)||e.length>0)}},{key:"isPending",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state;return Object.keys(e.pending).length>0}},{key:"isParentPending",value:function(){var e=this.context.resolver;return!!e&&(e.isPending()||e.isParentPending())}},{key:"onResolve",value:function(e){return this.props.onResolve?this.props.onResolve(e):this.context.resolver?this.context.resolver.onResolve(e):e}},{key:"render",value:function(){return!!this[HAS_RESOLVED]&&(this.isPending(this.state)&&this.resolve(this.state),this.props.children(_extends({},this.props.props)))}},{key:"resolve",value:function(e){var t=this,n=this.props.props,r=Object.keys(e.pending).map(function(t){return{name:t,func:e.pending[t]}}),o=r.map(function(e){return(0,e.func)(n)}),s=Promise.all(o).then(function(e){return e.reduce(function(e,t,n){return e[r[n].name]=!0,e},{})});(s=this.onResolve(s)).then(function(n){if(t[HAS_RESOLVED]=!0,!t[IS_CLIENT])return!1;var r={pending:{},resolved:_extends({},e.resolved,n)};t.setAtomicState(r)})}},{key:"shouldComponentUpdate",value:function(e,t){return!this.isParentPending()&&(!this.isPending(t)&&this[HAS_RESOLVED])}},{key:"setAtomicState",value:function(e){this.unMounted||this.setState(e)}}]),t}(React.Component);Resolver.childContextTypes={resolver:PropTypes.object},Resolver.contextTypes={resolver:PropTypes.object},Resolver.defaultProps={props:{},resolve:{}},Resolver.displayName="Resolver",Resolver.propTypes={children:PropTypes.func.isRequired,props:PropTypes.object,resolve:PropTypes.object},Resolver.renderClient=function(e,t){ReactDOM.hydrate(React.createElement(Resolver,null,e),t)},Resolver.renderServer=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=[];return server.renderToStaticMarkup(React.createElement(Resolver,{onResolve:function(e){return n.push(e),Promise.resolve(!0)}},e)),Promise.all(n).then(function(n){var r={};n.forEach(function(e){return Object.keys(e).forEach(function(t){r[t]=e[t]})});var o=_extends({},t,r);if(Object.keys(t).length<Object.keys(o).length)return Resolver.renderServer(e,o);var s=function(t){function n(){return classCallCheck(this,n),possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return inherits(n,t),createClass(n,[{key:"render",value:function(){return React.createElement(Resolver,null,e)}}]),n}(React.Component);return s.displayName="Resolved",s})};var resolve=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r="object"===(void 0===e?"undefined":_typeof(e))?e:defineProperty({},e,t),o=Object.keys(r).map(capitalize).join(""),s="object"===(void 0===e?"undefined":_typeof(e))&&"boolean"==typeof t?t:n;return function(e){var t,n;return n=t=function(t){function n(){return classCallCheck(this,n),possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return inherits(n,t),createClass(n,[{key:"render",value:function(){return React.createElement(Resolver,{props:this.props,resolve:r,cache:s},function(t){return React.createElement(e,t)})}}]),n}(React.Component),t.displayName=o+"Resolver",n}},canUseDom=function(){return"undefined"!=typeof window},capitalize$1=function(e){return e.replace(/^./,function(e){return e.toUpperCase()})},hasOwnProperty$1=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},client=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r="string"==typeof e?[e]:e,o=r.map(capitalize$1).join("");return function(e){var s,i;return i=s=function(o){function s(e,t){classCallCheck(this,s);var o=possibleConstructorReturn(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,e,t));return o.enqueue=function(e){return o.queue.push(e),e},o.isLoaded=function(){var e=!0;return r.forEach(function(t){hasOwnProperty$1(o.props,t)&&o.props[t]||(e=!1)}),e},o.queue=[],o.state={bypass:!canUseDom()&&!n||!1,loaded:o.isLoaded(e)},o}return inherits(s,o),createClass(s,[{key:"componentDidMount",value:function(){n&&n(this.props)}},{key:"render",value:function(){var n=this;return this.state.bypass||this.isLoaded()?React.createElement(e,this.props):React.createElement("div",null,React.createElement(t,null),React.createElement("div",{style:{display:"none"}},React.createElement(Resolver,{onResolve:this.enqueue},function(t){return React.createElement(e,_extends({},n.props,t))})))}}]),s}(React.Component),s.displayName=o+"ClientResolver",s.contextTypes={resolver:PropTypes.instanceOf(Resolver)},i}};exports.resolve=resolve,exports.client=client,exports.Resolver=Resolver; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var React=_interopDefault(require("react")),PropTypes=_interopDefault(require("prop-types")),ReactDOM=_interopDefault(require("react-dom")),server=require("react-dom/server"),canUseDom=function(){return"undefined"!=typeof window},capitalize=function(e){return e.replace(/^./,function(e){return e.toUpperCase()})},hasOwnProperty=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),defineProperty=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},inherits=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)},possibleConstructorReturn=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t},HAS_RESOLVED="ReactResolver.HAS_RESOLVED",IS_CLIENT="ReactResolver.IS_CLIENT",Resolver=function(e){function t(e,n){classCallCheck(this,t);var r=possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e,n));return r.unMounted=!0,r[HAS_RESOLVED]=!1,r[IS_CLIENT]=!1,r.state=r.computeState(r.props,{pending:{},resolved:{}}),r.isPending(r.state)?(r.resolve(r.state),r[HAS_RESOLVED]=!1):r[HAS_RESOLVED]=!0,r}return inherits(t,e),createClass(t,[{key:"cached",value:function(e){var t=this.props,n=t.props;if(t.cache||!canUseDom()){if(hasOwnProperty(n,e))return n[e];if(this.context.resolver)return this.context.resolver.cached(e)}return null}},{key:"componentWillMount",value:function(){this.unMounted=!1}},{key:"componentDidMount",value:function(){this[IS_CLIENT]=!0}},{key:"componentWillUnmount",value:function(){this.unMounted=!0}},{key:"componentWillReceiveProps",value:function(e){var t=this.computeState(e,this.state),n={pending:t.pending,resolved:t.resolved};this.setAtomicState(n)}},{key:"computeState",value:function(e,t){var n=this,r=e.resolve,o=t;return Object.keys(r).forEach(function(e){var s=n.cached(e);hasOwnProperty(t.resolved,e)||hasOwnProperty(t.pending,e)||n.isValidCache(s)?s&&(o.resolved[e]=!0):o.pending[e]=r[e]}),o}},{key:"getChildContext",value:function(){return{resolver:this}}},{key:"isValidCache",value:function(e){return null!==e&&void 0!==e&&("object"!==(void 0===e?"undefined":_typeof(e))||Object.keys(e).length>0)&&(!Array.isArray(e)||e.length>0)}},{key:"isPending",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.state;return Object.keys(e.pending).length>0}},{key:"isParentPending",value:function(){var e=this.context.resolver;return!!e&&(e.isPending()||e.isParentPending())}},{key:"onResolve",value:function(e){return this.props.onResolve?this.props.onResolve(e):this.context.resolver?this.context.resolver.onResolve(e):e}},{key:"render",value:function(){return!!this[HAS_RESOLVED]&&(this.isPending(this.state)&&this.resolve(this.state),this.props.children(_extends({},this.props.props)))}},{key:"resolve",value:function(e){var t=this,n=this.props.props,r=Object.keys(e.pending).map(function(t){return{name:t,func:e.pending[t]}}),o=r.map(function(e){return(0,e.func)(n)}),s=Promise.all(o).then(function(e){return e.reduce(function(e,t,n){return e[r[n].name]=!0,e},{})});(s=this.onResolve(s)).then(function(n){if(t[HAS_RESOLVED]=!0,!t[IS_CLIENT])return!1;var r={pending:{},resolved:_extends({},e.resolved,n)};t.setAtomicState(r)})}},{key:"shouldComponentUpdate",value:function(e,t){return!this.isParentPending()&&(!this.isPending(t)&&this[HAS_RESOLVED])}},{key:"setAtomicState",value:function(e){this.unMounted||this.setState(e)}}]),t}(React.Component);Resolver.childContextTypes={resolver:PropTypes.object},Resolver.contextTypes={resolver:PropTypes.object},Resolver.defaultProps={props:{},resolve:{}},Resolver.displayName="Resolver",Resolver.propTypes={children:PropTypes.func.isRequired,props:PropTypes.object,resolve:PropTypes.object},Resolver.renderClient=function(e,t){ReactDOM.hydrate(React.createElement(Resolver,null,e),t)},Resolver.renderServer=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=[];return server.renderToStaticMarkup(React.createElement(Resolver,{onResolve:function(e){return n.push(e),Promise.resolve(!0)}},e)),Promise.all(n).then(function(n){var r={};n.forEach(function(e){return Object.keys(e).forEach(function(t){r[t]=e[t]})});var o=_extends({},t,r);if(Object.keys(t).length<Object.keys(o).length)return Resolver.renderServer(e,o);var s=function(t){function n(){return classCallCheck(this,n),possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return inherits(n,t),createClass(n,[{key:"render",value:function(){return React.createElement(Resolver,null,e)}}]),n}(React.Component);return s.displayName="Resolved",s})};var resolve=function(e,t){var n=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],r="object"===(void 0===e?"undefined":_typeof(e))?e:defineProperty({},e,t),o=Object.keys(r).map(capitalize).join(""),s="object"===(void 0===e?"undefined":_typeof(e))&&"boolean"==typeof t?t:n;return function(e){var t,n;return n=t=function(t){function n(){return classCallCheck(this,n),possibleConstructorReturn(this,(n.__proto__||Object.getPrototypeOf(n)).apply(this,arguments))}return inherits(n,t),createClass(n,[{key:"render",value:function(){return React.createElement(Resolver,{props:this.props,resolve:r,cache:s},function(t){return React.createElement(e,t)})}}]),n}(React.Component),t.displayName=o+"Resolver",n}},client=function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r="string"==typeof e?[e]:e,o=r.map(capitalize).join("");return function(e){var s,i;return i=s=function(o){function s(e,t){classCallCheck(this,s);var o=possibleConstructorReturn(this,(s.__proto__||Object.getPrototypeOf(s)).call(this,e,t));return o.enqueue=function(e){return o.queue.push(e),e},o.isLoaded=function(){var e=!0;return r.forEach(function(t){hasOwnProperty(o.props,t)&&o.props[t]||(e=!1)}),e},o.queue=[],o.state={bypass:!canUseDom()&&!n||"test"===process.env.NODE_ENV,loaded:o.isLoaded(e)},o}return inherits(s,o),createClass(s,[{key:"componentDidMount",value:function(){n&&n(this.props)}},{key:"render",value:function(){var r=this;return this.state.bypass||this.isLoaded()?React.createElement(e,this.props):React.createElement(React.Fragment,null,React.createElement(t,null),!n&&React.createElement("div",{style:{display:"none"}},React.createElement(Resolver,{onResolve:this.enqueue},function(t){return React.createElement(e,_extends({},r.props,t))})))}}]),s}(React.Component),s.displayName=o+"ClientResolver",s.contextTypes={resolver:PropTypes.instanceOf(Resolver)},i}};exports.resolve=resolve,exports.client=client,exports.Resolver=Resolver; | ||
//# sourceMappingURL=react-esc-resolver.production.js.map |
{ | ||
"name": "react-esc-resolver", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Easy to use Client and Server Resolver", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
58419
485
3