UNPKG

react-async-call

Version:
3 lines (2 loc) 11.3 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],t):t(e.ReactAsyncCall={},e.React,e.PropTypes)}(this,function(e,l,t){"use strict";var d="default"in l?l.default:l,r="default"in t?t.default:t;function n(e){return function(){return e}}function o(){}o.thatReturns=n,o.thatReturnsFalse=n(!1),o.thatReturnsTrue=n(!0),o.thatReturnsNull=n(null),o.thatReturnsThis=function(){return this},o.thatReturnsArgument=function(e){return e};var h=o,u=Object.prototype.hasOwnProperty;function i(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}var a=function(e,t){if(i(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(var o=0;o<n.length;o++)if(!u.call(t,n[o])||!i(e[n[o]],t[n[o]]))return!1;return!0},c=function(e){return!!(e&&e.constructor&&e.call&&e.apply)},p=function(e,t){return(c(e.children)?e.children(t):e.children)||null},f=function(e,t){return c(e.children)&&e.children(t)||null},v=function(e,r,o,t,n){return function t(n){return l.createElement(e,null,function(e){return y(e,s,t.displayName,r),o(n,e)||null})}},s=void 0;function y(e,t,n,r,o,u,i,s){var a;if(!e)throw(a=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.")).framesToPop=1,a}var m="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function _(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function g(e,t){return e(t={exports:{}},t.exports),t.exports}var R="__global_unique_id__",b=function(){return m[R]=(m[R]||0)+1},w=g(function(e,t){t.__esModule=!0;n(d);var s=n(r),a=n(b);n(h);function n(e){return e&&e.__esModule?e:{default:e}}function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(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}function p(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)}var f=1073741823;t.default=function(e,i){var t,n,r="__create-react-context-"+(0,a.default)()+"__",o=function(s){function a(){var e,t,n,r;l(this,a);for(var o=arguments.length,u=Array(o),i=0;i<o;i++)u[i]=arguments[i];return(e=t=c(this,s.call.apply(s,[this].concat(u)))).emitter=(n=t.props.value,r=[],{on:function(e){r.push(e)},off:function(t){r=r.filter(function(e){return e!==t})},get:function(){return n},set:function(e,t){n=e,r.forEach(function(e){return e(n,t)})}}),c(t,e)}return p(a,s),a.prototype.getChildContext=function(){var e;return(e={})[r]=this.emitter,e},a.prototype.componentWillReceiveProps=function(e){if(this.props.value!==e.value){var t=this.props.value,n=e.value,r=void 0;((o=t)===(u=n)?0!==o||1/o==1/u:o!=o&&u!=u)?r=0:(r="function"==typeof i?i(t,n):f,0!=(r|=0)&&this.emitter.set(e.value,r))}var o,u},a.prototype.render=function(){return this.props.children},a}(d.Component);o.childContextTypes=((t={})[r]=s.default.object.isRequired,t);var u=function(u){function i(){var e,n;l(this,i);for(var t=arguments.length,r=Array(t),o=0;o<t;o++)r[o]=arguments[o];return(e=n=c(this,u.call.apply(u,[this].concat(r)))).state={value:n.getValue()},n.onUpdate=function(e,t){0!=((0|n.observedBits)&t)&&n.setState({value:n.getValue()})},c(n,e)}return p(i,u),i.prototype.componentWillReceiveProps=function(e){var t=e.observedBits;this.observedBits=null==t?f:t},i.prototype.componentDidMount=function(){this.context[r]&&this.context[r].on(this.onUpdate);var e=this.props.observedBits;this.observedBits=null==e?f:e},i.prototype.componentWillUnmount=function(){this.context[r]&&this.context[r].off(this.onUpdate)},i.prototype.getValue=function(){return this.context[r]?this.context[r].get():e},i.prototype.render=function(){return e=this.props.children,(Array.isArray(e)?e[0]:e)(this.state.value);var e},i}(d.Component);return u.contextTypes=((n={})[r]=s.default.object,n),{Provider:o,Consumer:u}},e.exports=t.default});_(w);var S=_(g(function(e,t){t.__esModule=!0;var n=o(d),r=o(w);function o(e){return e&&e.__esModule?e:{default:e}}t.default=n.default.createContext||r.default,e.exports=t.default}));function j(){var e=this.constructor.getDerivedStateFromProps(this.props,this.state);null!=e&&this.setState(e)}function P(n){this.setState(function(e){var t=this.constructor.getDerivedStateFromProps(n,e);return null!=t?t:null}.bind(this))}function x(e,t){try{var n=this.props,r=this.state;this.props=e,this.state=t,this.__reactInternalSnapshotFlag=!0,this.__reactInternalSnapshot=this.getSnapshotBeforeUpdate(n,r)}finally{this.props=n,this.state=r}}x.__suppressDeprecationWarning=P.__suppressDeprecationWarning=j.__suppressDeprecationWarning=!0;var U=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},E=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},O=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)},F=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},W="initialValue",C=function(e,t){var n=S(),r=n.Consumer,o=n.Provider,u=function(u){function i(){var e,t;U(this,i);for(var n=arguments.length,r=Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t=F(this,u.call.apply(u,[this].concat(r)))).state={hasResult:!1,wasResolved:t.props.resolved},t.reset=function(e){t.setState(s(t.props)),e&&e()},F(t,e)}return O(i,u),i.prototype.componentDidMount=function(){var e=this.props,t=e.resolved;(t||e.hasOwnProperty(W))&&this.setState({hasResult:!0,result:t?e.result:e.initialValue,wasResolved:t})},i.getDerivedStateFromProps=function(e,t){var n=e.resolved;return e.reset?E({},s(e),{wasResolved:n}):n&&!t.wasResolved?t.hasResult?{result:e.reduce(t.result,e.result),wasResolved:n}:{hasResult:!0,result:e.result,wasResolved:n}:n!==t.wasResolved?{wasResolved:n}:null},i.prototype.render=function(){var e=this.state,t=this.props,n=E({hasResult:e.hasResult,reset:t.resetFn},e.hasResult?{result:e.result}:{});return l.createElement(o,{value:n},p(t,n))},i}(l.Component),s=function(e){return e.hasOwnProperty(W)?{hasResult:!0,result:e.initialValue}:{hasResult:!1}},a=function(e){var t=e.prototype;if(!t||!t.isReactComponent)throw new Error("Can only polyfill class components");if("function"!=typeof e.getDerivedStateFromProps&&"function"!=typeof t.getSnapshotBeforeUpdate)return e;var n=null,r=null,o=null;if("function"==typeof t.componentWillMount?n="componentWillMount":"function"==typeof t.UNSAFE_componentWillMount&&(n="UNSAFE_componentWillMount"),"function"==typeof t.componentWillReceiveProps?r="componentWillReceiveProps":"function"==typeof t.UNSAFE_componentWillReceiveProps&&(r="UNSAFE_componentWillReceiveProps"),"function"==typeof t.componentWillUpdate?o="componentWillUpdate":"function"==typeof t.UNSAFE_componentWillUpdate&&(o="UNSAFE_componentWillUpdate"),null!==n||null!==r||null!==o){var u=e.displayName||e.name,i="function"==typeof e.getDerivedStateFromProps?"getDerivedStateFromProps()":"getSnapshotBeforeUpdate()";throw Error("Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n"+u+" uses "+i+" but also contains the following legacy lifecycles:"+(null!==n?"\n "+n:"")+(null!==r?"\n "+r:"")+(null!==o?"\n "+o:"")+"\n\nThe above lifecycles should be removed. Learn more about this warning here:\nhttps://fb.me/react-async-component-lifecycle-hooks")}if("function"==typeof e.getDerivedStateFromProps&&(t.componentWillMount=j,t.componentWillReceiveProps=P),"function"==typeof t.getSnapshotBeforeUpdate){if("function"!=typeof t.componentDidUpdate)throw new Error("Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype");t.componentWillUpdate=x;var s=t.componentDidUpdate;t.componentDidUpdate=function(e,t,n){var r=this.__reactInternalSnapshotFlag?this.__reactInternalSnapshot:n;s.call(this,e,t,r)}}return e}(u),i=function(u){function i(){var e,t;U(this,i);for(var n=arguments.length,r=Array(n),o=0;o<n;o++)r[o]=arguments[o];return(e=t=F(this,u.call.apply(u,[this].concat(r)))).reset=function(){var e=!(0<arguments.length&&void 0!==arguments[0])||arguments[0];t.ref.reset(e&&t._execute)},F(t,e)}return O(i,u),i.prototype.render=function(){var t=this;return l.createElement(e,null,function(e){return y(e),h(!t.props.hasOwnProperty("reset"),void 0),t._execute=e.execute,l.createElement(a,E({ref:function(e){return t.ref=e},resetFn:t.reset},t.props,e))})},i}(l.Component);return i.defaultProps={reduce:function(e,t){return t}},i.HasResult=v(r,i.displayName,function(e,t){return t.hasResult&&f(e,{result:t.result})}),i.Resetter=v(r,i.displayName,function(e,t){return f(e,{reset:t.reset})}),i};e.default=function(s,e){var t=S(),n=t.Provider,r=t.Consumer,o=function(o){function u(){var e,i;U(this,u);for(var t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];return(e=i=F(this,o.call.apply(o,[this].concat(n)))).state={running:!0,rejected:!1,resolved:!1},i._callQueryFunc=function(e){i.setState({running:!0,rejected:!1,resolved:!1});var t=s(e);y(t&&t.then&&c(t.then)),t.then(function(e){i._mounted&&i.setState({running:!1,rejected:!1,resolved:!0,result:e})},function(e){i._mounted&&i.setState({running:!1,rejected:!0,rejectReason:e})})},i._getState=function(){var e=i.state,t=e.running,n=e.resolved,r=e.rejected,o=e.result,u=e.rejectReason;return o=n?{result:o}:{},u=r?{rejectReason:u}:{},E({running:t,rejected:r,resolved:n,execute:i.execute},o,u)},i.execute=function(){i._callQueryFunc(i.props.params)},F(i,e)}return O(u,o),u.prototype.componentDidMount=function(){y(c(s)),this._mounted=!0;var e=this.props;e.lazy||this._callQueryFunc(e.params)},u.prototype.componentWillUnmount=function(){this._mounted=!1},u.prototype.componentDidUpdate=function(e){var t=this.props,n=t.params;t.lazy||a(n,e.params)||this._callQueryFunc(n)},u.prototype.render=function(){var e=this._getState(),t=this.props;return l.createElement(n,{value:e},void 0!==t.children&&p(t,e))},u}(l.Component);return o.Running=v(r,!1,function(e,t){return t.running&&e.children}),o.Resolved=v(r,!1,function(e,t){return t.resolved&&p(e,{result:t.result})}),o.Rejected=v(r,!1,function(e,t){return t.rejected&&p(e,{rejectReason:t.rejectReason})}),o.Executor=v(r,!1,function(e,t){return f(e,{execute:t.execute})}),o.State=v(r,!1,f),o.ResultStore=C(r),o.Completed=v(r,!1,function(e,t){return(t.resolved||t.rejected)&&e.children}),o},Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=react-async-call.production.min.js.map