Socket
Socket
Sign inDemoInstall

@department/apollo-component

Package Overview
Dependencies
6
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.9.0 to 1.9.1

2

dist/index.js

@@ -1,2 +0,2 @@

"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t,e){for(var o in t)if(t[o]!==e[o])return!1;for(var r in e)if(!(r in t))return!1;return!0}function o(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}var r=require("react"),n=t(r),i=t(require("prop-types")),s=function(t){return"object"==typeof t&&t.constructor===Object},p=function(t){function r(e){t.call(this,e),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this),this.state={skipped:this.shouldSkip(e)}}return t&&(r.__proto__=t),r.prototype=Object.create(t&&t.prototype),r.prototype.constructor=r,r.prototype.componentWillMount=function(){var t=this.context.apollo||{},e=t.client,o=t.queued;if(!e)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");this.observable=e.watchQuery(u(this.props)),!this.props.lazy&&o&&o.push(this.observable)},r.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},r.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this.observable&&delete this.observable},r.prototype.componentWillReceiveProps=function(t,o){return t.gql!==this.props.gql?this.request(t):"boolean"==typeof t.skip&&t.skip!==this.props.skip?this.request(t):e(this.props.variables,t.variables)?void 0:this.request(t)},r.prototype.request=function(t){var e=this,r=this.shouldSkip(t);if(this.setState({skipped:r}),!r&&(this.observable.setOptions(u(t)),!this.subscription)){var n=o(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:n,error:n})}},r.prototype.shouldSkip=function(t){return"function"==typeof t.skip?!!t.skip(t.variables):"boolean"==typeof t.skip&&t.skip},r.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,o=t.error,r=this.state.skipped,n={};return o?Object.assign(n,(this.observable.getLastResult()||{}).data):Object.assign(n,this.previousData,t.data),this.previousData=n,{skipped:r,loading:e,error:o,data:n}},r.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable){var e=this.observable.refetch(s(t)?t:void 0);return this.props.wait||this.forceUpdate(),e}},r.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},r.prototype.render=function(){var t=this.getState();if(this.props.wait&&t.loading)return null;if(this.props.fail&&t.error)throw t.error;return(this.props.render||this.props.children)(Object.assign({},t,{refetch:this.refetch,fetchMore:this.fetchMore}))},r}(n.Component);p.contextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired},p.propTypes={gql:i.object.isRequired,variables:i.object,wait:i.bool,lazy:i.bool,skip:i.oneOfType([i.bool,i.func]),fail:i.bool,pollInterval:i.number,fetchPolicy:i.oneOf(["cache-first","cache-and-network","network-only","cache-only"]),errorPolicy:i.oneOf(["none","ignore","all"]),notifyOnNetworkStatusChange:i.bool,context:i.object,children:i.func,render:i.func};var u=function(t){return{query:t.gql,variables:t.variables,pollInterval:t.pollInterval,fetchPolicy:t.fetchPolicy,errorPolicy:t.errorPolicy,notifyOnNetworkStatusChange:t.notifyOnNetworkStatusChange,context:t.context}},c=function(t){function e(){t.call(this),this.mutate=this.mutate.bind(this),this.state={data:{},loading:!1}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentDidMount=function(){this.mounted=!0},e.prototype.componentWillUnmount=function(){this.mounted=!1},e.prototype.mutate=function(t){var e=this;s(t)||(t=void 0),void 0===t&&(t=this.props.variables);var o=this.context.apollo.client,r=this.props,n=r.gql,i=r.refetchQueries,p=r.optimisticResponse,u=r.update,c=o.mutate({mutation:n,refetchQueries:i,optimisticResponse:p,update:u,variables:t});return this.setState({loading:!0}),c.then(function(t){e.mounted&&e.setState(Object.assign({},t,{error:null,loading:!1}))}).catch(function(t){e.mounted&&e.setState({error:t,loading:!1})}),c},e.prototype.render=function(){if(this.props.fail&&this.state.error)throw this.state.error;return(this.props.render||this.props.children)(this.mutate,this.state)},e}(n.Component);c.contextTypes={apollo:i.shape({client:i.object.isRequired}).isRequired},c.propTypes={gql:i.object.isRequired,variables:i.object,fail:i.bool,refetchQueries:i.array,optimisticResponse:i.func,update:i.func,children:i.func,render:i.func};var a=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){var t=this.props,e=t.client,o=t.queued,r=this.context.apollo;return r&&r.queued&&(o=r.queued),{apollo:{client:e,queued:o}}},e.prototype.render=function(){return this.props.children},e}(n.Component);a.contextTypes={apollo:i.shape({queued:i.array})},a.childContextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired};var l=function(t){this.mocks=t};l.prototype.mutate=function(t){return new Promise(function(t,e){return t()}.bind(this))},l.prototype.watchQuery=function(t){var e=this;return{refetch:function(t){return new Promise(function(t,e){return t()}.bind(e))},fetchMore:function(t){return new Promise(function(t,e){return t()}.bind(e))},setOptions:function(){},getLastResult:function(){},currentResult:function(){return{loading:!1,error:null,data:{}}},subscribe:function(t){t.next,t.error;return{unsubscribe:function(){}}}}};var h=function(t,e,o){void 0===o&&(o={});var n=o.maxDepth;void 0===n&&(n=1/0);var i=function(o){if(void 0===o&&(o=0),o<n){var s=[];f(r.createElement(a,{client:t,queued:s},e));var p=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(p.length)return Promise.all(p).then(function(){return i(o+1)})}return Promise.resolve()};return i()},f=function(t,e){if(void 0===e&&(e={}),Array.isArray(t))t.forEach(function(t){return t&&f(t,e)});else if("function"==typeof t.type){var o,n=e,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var p=new i(s,e);p.props=p.props||s,p.context=p.context||e,p.state=p.state||null,p.setState=function(t){"function"==typeof t&&(t=t(p.state,p.props,p.context)),p.state=Object.assign({},p.state,t)},p.componentWillMount&&p.componentWillMount(),p.getChildContext&&(n=Object.assign({},e,p.getChildContext())),o=p.render()}else o=i(s,e);Array.of(o).forEach(function(t){return t&&f(t,n)})}else t.props&&t.props.children&&r.Children.forEach(t.props.children,function(t){return t&&f(t,e)})};exports.MockClient=l,exports.Query=p,exports.Mutate=c,exports.Provider=a,exports.renderState=h;
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t,e){for(var o in t)if(t[o]!==e[o])return!1;for(var r in e)if(!(r in t))return!1;return!0}function o(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}var r=require("react"),n=t(r),i=t(require("prop-types")),s=function(t){return"object"==typeof t&&t.constructor===Object},p=function(t){function r(e){t.call(this,e),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this),this.state={skipped:this.shouldSkip(e)}}t&&(r.__proto__=t),(r.prototype=Object.create(t&&t.prototype)).constructor=r;var n={observable:{configurable:!0}};return r.prototype.componentWillMount=function(){var t=(this.context.apollo||{}).queued;this.props.lazy||this.state.skipped||!t||t.push(this.observable)},r.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},r.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this._o&&delete this._o},r.prototype.componentWillReceiveProps=function(t,o){return t.gql!==this.props.gql?this.request(t):"boolean"==typeof t.skip&&t.skip!==this.props.skip?this.request(t):e(this.props.variables,t.variables)?void 0:this.request(t)},n.observable.get=function(){if(this._o)return this._o;var t=(this.context.apollo||{}).client;if(!t)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");return this._o=t.watchQuery(u(this.props))},r.prototype.request=function(t){var e=this,r=this.shouldSkip(t);if(this.setState({skipped:r}),!r&&(this.observable.setOptions(u(t)),!this.subscription)){var n=o(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:n,error:n})}},r.prototype.shouldSkip=function(t){return"function"==typeof t.skip?!!t.skip(t.variables):"boolean"==typeof t.skip&&t.skip},r.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,o=t.error,r=this.state.skipped,n={};return o?Object.assign(n,(this.observable.getLastResult()||{}).data):Object.assign(n,this.previousData,t.data),this.previousData=n,{skipped:r,loading:e,error:o,data:n}},r.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable){var e=this.observable.refetch(s(t)?t:void 0);return this.props.wait||this.forceUpdate(),e}},r.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},r.prototype.render=function(){var t=this.getState();if(this.props.wait&&t.loading)return null;if(this.props.fail&&t.error)throw t.error;return(this.props.render||this.props.children)(Object.assign({},t,{refetch:this.refetch,fetchMore:this.fetchMore}))},Object.defineProperties(r.prototype,n),r}(n.Component);p.contextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired},p.propTypes={gql:i.object.isRequired,variables:i.object,wait:i.bool,lazy:i.bool,skip:i.oneOfType([i.bool,i.func]),fail:i.bool,pollInterval:i.number,fetchPolicy:i.oneOf(["cache-first","cache-and-network","network-only","cache-only"]),errorPolicy:i.oneOf(["none","ignore","all"]),notifyOnNetworkStatusChange:i.bool,context:i.object,children:i.func,render:i.func};var u=function(t){return{query:t.gql,variables:t.variables,pollInterval:t.pollInterval,fetchPolicy:t.fetchPolicy,errorPolicy:t.errorPolicy,notifyOnNetworkStatusChange:t.notifyOnNetworkStatusChange,context:t.context}},c=function(t){function e(){t.call(this),this.mutate=this.mutate.bind(this),this.state={data:{},loading:!1}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentDidMount=function(){this.mounted=!0},e.prototype.componentWillUnmount=function(){this.mounted=!1},e.prototype.mutate=function(t){var e=this;s(t)||(t=void 0),void 0===t&&(t=this.props.variables);var o=this.context.apollo.client,r=this.props,n=r.gql,i=r.refetchQueries,p=r.optimisticResponse,u=r.update,c=o.mutate({mutation:n,refetchQueries:i,optimisticResponse:p,update:u,variables:t});return this.setState({loading:!0}),c.then(function(t){e.mounted&&e.setState(Object.assign({},t,{error:null,loading:!1}))}).catch(function(t){e.mounted&&e.setState({error:t,loading:!1})}),c},e.prototype.render=function(){if(this.props.fail&&this.state.error)throw this.state.error;return(this.props.render||this.props.children)(this.mutate,this.state)},e}(n.Component);c.contextTypes={apollo:i.shape({client:i.object.isRequired}).isRequired},c.propTypes={gql:i.object.isRequired,variables:i.object,fail:i.bool,refetchQueries:i.array,optimisticResponse:i.func,update:i.func,children:i.func,render:i.func};var a=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){var t=this.props,e=t.client,o=t.queued,r=this.context.apollo;return r&&r.queued&&(o=r.queued),{apollo:{client:e,queued:o}}},e.prototype.render=function(){return this.props.children},e}(n.Component);a.contextTypes={apollo:i.shape({queued:i.array})},a.childContextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired};var l=function(t){this.mocks=t};l.prototype.mutate=function(t){return new Promise(function(t,e){return t()}.bind(this))},l.prototype.watchQuery=function(t){var e=this;return{refetch:function(t){return new Promise(function(t,e){return t()}.bind(e))},fetchMore:function(t){return new Promise(function(t,e){return t()}.bind(e))},setOptions:function(){},getLastResult:function(){},currentResult:function(){return{loading:!1,error:null,data:{}}},subscribe:function(t){t.next,t.error;return{unsubscribe:function(){}}}}};var h=function(t,e,o){void 0===o&&(o={});var n=o.maxDepth;void 0===n&&(n=1/0);var i=function(o){if(void 0===o&&(o=0),o<n){var s=[];f(r.createElement(a,{client:t,queued:s},e));var p=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(p.length)return Promise.all(p).then(function(){return i(o+1)})}return Promise.resolve()};return i()},f=function(t,e){if(void 0===e&&(e={}),Array.isArray(t))t.forEach(function(t){return t&&f(t,e)});else if("function"==typeof t.type){var o,n=e,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var p=new i(s,e);p.props=p.props||s,p.context=p.context||e,p.state=p.state||null,p.setState=function(t){"function"==typeof t&&(t=t(p.state,p.props,p.context)),p.state=Object.assign({},p.state,t)},p.componentWillMount&&p.componentWillMount(),p.getChildContext&&(n=Object.assign({},e,p.getChildContext())),o=p.render()}else o=i(s,e);Array.of(o).forEach(function(t){return t&&f(t,n)})}else t.props&&t.props.children&&r.Children.forEach(t.props.children,function(t){return t&&f(t,e)})};exports.MockClient=l,exports.Query=p,exports.Mutate=c,exports.Provider=a,exports.renderState=h;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],e):e(t._department_apollo_component={},t.react,t.PropTypes)}(this,function(t,e,o){"use strict";var r="default"in e?e.default:e;o=o&&o.hasOwnProperty("default")?o.default:o;var n=function(t){return"object"==typeof t&&t.constructor===Object},i=function(t){function e(e){t.call(this,e),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this),this.state={skipped:this.shouldSkip(e)}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentWillMount=function(){var t=this.context.apollo||{},e=t.client,o=t.queued;if(!e)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");this.observable=e.watchQuery(s(this.props)),!this.props.lazy&&o&&o.push(this.observable)},e.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},e.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this.observable&&delete this.observable},e.prototype.componentWillReceiveProps=function(t,e){return t.gql!==this.props.gql?this.request(t):"boolean"==typeof t.skip&&t.skip!==this.props.skip?this.request(t):function(t,e){for(var o in t)if(t[o]!==e[o])return!1;for(var r in e)if(!(r in t))return!1;return!0}(this.props.variables,t.variables)?void 0:this.request(t)},e.prototype.request=function(t){var e=this,o=this.shouldSkip(t);if(this.setState({skipped:o}),!o&&(this.observable.setOptions(s(t)),!this.subscription)){var r=function(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:r,error:r})}},e.prototype.shouldSkip=function(t){return"function"==typeof t.skip?!!t.skip(t.variables):"boolean"==typeof t.skip&&t.skip},e.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,o=t.error,r=this.state.skipped,n={};return o?Object.assign(n,(this.observable.getLastResult()||{}).data):Object.assign(n,this.previousData,t.data),this.previousData=n,{skipped:r,loading:e,error:o,data:n}},e.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable){var e=this.observable.refetch(n(t)?t:void 0);return this.props.wait||this.forceUpdate(),e}},e.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},e.prototype.render=function(){var t=this.getState();if(this.props.wait&&t.loading)return null;if(this.props.fail&&t.error)throw t.error;return(this.props.render||this.props.children)(Object.assign({},t,{refetch:this.refetch,fetchMore:this.fetchMore}))},e}(r.Component);i.contextTypes={apollo:o.shape({client:o.object.isRequired,queued:o.array}).isRequired},i.propTypes={gql:o.object.isRequired,variables:o.object,wait:o.bool,lazy:o.bool,skip:o.oneOfType([o.bool,o.func]),fail:o.bool,pollInterval:o.number,fetchPolicy:o.oneOf(["cache-first","cache-and-network","network-only","cache-only"]),errorPolicy:o.oneOf(["none","ignore","all"]),notifyOnNetworkStatusChange:o.bool,context:o.object,children:o.func,render:o.func};var s=function(t){return{query:t.gql,variables:t.variables,pollInterval:t.pollInterval,fetchPolicy:t.fetchPolicy,errorPolicy:t.errorPolicy,notifyOnNetworkStatusChange:t.notifyOnNetworkStatusChange,context:t.context}},p=function(t){function e(){t.call(this),this.mutate=this.mutate.bind(this),this.state={data:{},loading:!1}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentDidMount=function(){this.mounted=!0},e.prototype.componentWillUnmount=function(){this.mounted=!1},e.prototype.mutate=function(t){var e=this;n(t)||(t=void 0),void 0===t&&(t=this.props.variables);var o=this.context.apollo.client,r=this.props,i=r.gql,s=r.refetchQueries,p=r.optimisticResponse,u=r.update,a=o.mutate({mutation:i,refetchQueries:s,optimisticResponse:p,update:u,variables:t});return this.setState({loading:!0}),a.then(function(t){e.mounted&&e.setState(Object.assign({},t,{error:null,loading:!1}))}).catch(function(t){e.mounted&&e.setState({error:t,loading:!1})}),a},e.prototype.render=function(){if(this.props.fail&&this.state.error)throw this.state.error;return(this.props.render||this.props.children)(this.mutate,this.state)},e}(r.Component);p.contextTypes={apollo:o.shape({client:o.object.isRequired}).isRequired},p.propTypes={gql:o.object.isRequired,variables:o.object,fail:o.bool,refetchQueries:o.array,optimisticResponse:o.func,update:o.func,children:o.func,render:o.func};var u=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){var t=this.props,e=t.client,o=t.queued,r=this.context.apollo;return r&&r.queued&&(o=r.queued),{apollo:{client:e,queued:o}}},e.prototype.render=function(){return this.props.children},e}(r.Component);u.contextTypes={apollo:o.shape({queued:o.array})},u.childContextTypes={apollo:o.shape({client:o.object.isRequired,queued:o.array}).isRequired};var a=function(t){this.mocks=t};a.prototype.mutate=function(t){return new Promise(function(t,e){return t()}.bind(this))},a.prototype.watchQuery=function(t){var e=this;return{refetch:function(t){return new Promise(function(t,e){return t()}.bind(e))},fetchMore:function(t){return new Promise(function(t,e){return t()}.bind(e))},setOptions:function(){},getLastResult:function(){},currentResult:function(){return{loading:!1,error:null,data:{}}},subscribe:function(t){t.next,t.error;return{unsubscribe:function(){}}}}};var c=function(t,o){if(void 0===o&&(o={}),Array.isArray(t))t.forEach(function(t){return t&&c(t,o)});else if("function"==typeof t.type){var r,n=o,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var p=new i(s,o);p.props=p.props||s,p.context=p.context||o,p.state=p.state||null,p.setState=function(t){"function"==typeof t&&(t=t(p.state,p.props,p.context)),p.state=Object.assign({},p.state,t)},p.componentWillMount&&p.componentWillMount(),p.getChildContext&&(n=Object.assign({},o,p.getChildContext())),r=p.render()}else r=i(s,o);Array.of(r).forEach(function(t){return t&&c(t,n)})}else t.props&&t.props.children&&e.Children.forEach(t.props.children,function(t){return t&&c(t,o)})};t.MockClient=a,t.Query=i,t.Mutate=p,t.Provider=u,t.renderState=function(t,o,r){void 0===r&&(r={});var n=r.maxDepth;void 0===n&&(n=1/0);var i=function(r){if(void 0===r&&(r=0),r<n){var s=[];c(e.createElement(u,{client:t,queued:s},o));var p=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(p.length)return Promise.all(p).then(function(){return i(r+1)})}return Promise.resolve()};return i()}});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],e):e(t._department_apollo_component={},t.react,t.PropTypes)}(this,function(t,e,o){"use strict";var r="default"in e?e.default:e;o=o&&o.hasOwnProperty("default")?o.default:o;var n=function(t){return"object"==typeof t&&t.constructor===Object},i=function(t){function e(e){t.call(this,e),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this),this.state={skipped:this.shouldSkip(e)}}t&&(e.__proto__=t),(e.prototype=Object.create(t&&t.prototype)).constructor=e;var o={observable:{configurable:!0}};return e.prototype.componentWillMount=function(){var t=(this.context.apollo||{}).queued;this.props.lazy||this.state.skipped||!t||t.push(this.observable)},e.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},e.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this._o&&delete this._o},e.prototype.componentWillReceiveProps=function(t,e){return t.gql!==this.props.gql?this.request(t):"boolean"==typeof t.skip&&t.skip!==this.props.skip?this.request(t):function(t,e){for(var o in t)if(t[o]!==e[o])return!1;for(var r in e)if(!(r in t))return!1;return!0}(this.props.variables,t.variables)?void 0:this.request(t)},o.observable.get=function(){if(this._o)return this._o;var t=(this.context.apollo||{}).client;if(!t)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");return this._o=t.watchQuery(s(this.props))},e.prototype.request=function(t){var e=this,o=this.shouldSkip(t);if(this.setState({skipped:o}),!o&&(this.observable.setOptions(s(t)),!this.subscription)){var r=function(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:r,error:r})}},e.prototype.shouldSkip=function(t){return"function"==typeof t.skip?!!t.skip(t.variables):"boolean"==typeof t.skip&&t.skip},e.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,o=t.error,r=this.state.skipped,n={};return o?Object.assign(n,(this.observable.getLastResult()||{}).data):Object.assign(n,this.previousData,t.data),this.previousData=n,{skipped:r,loading:e,error:o,data:n}},e.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable){var e=this.observable.refetch(n(t)?t:void 0);return this.props.wait||this.forceUpdate(),e}},e.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},e.prototype.render=function(){var t=this.getState();if(this.props.wait&&t.loading)return null;if(this.props.fail&&t.error)throw t.error;return(this.props.render||this.props.children)(Object.assign({},t,{refetch:this.refetch,fetchMore:this.fetchMore}))},Object.defineProperties(e.prototype,o),e}(r.Component);i.contextTypes={apollo:o.shape({client:o.object.isRequired,queued:o.array}).isRequired},i.propTypes={gql:o.object.isRequired,variables:o.object,wait:o.bool,lazy:o.bool,skip:o.oneOfType([o.bool,o.func]),fail:o.bool,pollInterval:o.number,fetchPolicy:o.oneOf(["cache-first","cache-and-network","network-only","cache-only"]),errorPolicy:o.oneOf(["none","ignore","all"]),notifyOnNetworkStatusChange:o.bool,context:o.object,children:o.func,render:o.func};var s=function(t){return{query:t.gql,variables:t.variables,pollInterval:t.pollInterval,fetchPolicy:t.fetchPolicy,errorPolicy:t.errorPolicy,notifyOnNetworkStatusChange:t.notifyOnNetworkStatusChange,context:t.context}},p=function(t){function e(){t.call(this),this.mutate=this.mutate.bind(this),this.state={data:{},loading:!1}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentDidMount=function(){this.mounted=!0},e.prototype.componentWillUnmount=function(){this.mounted=!1},e.prototype.mutate=function(t){var e=this;n(t)||(t=void 0),void 0===t&&(t=this.props.variables);var o=this.context.apollo.client,r=this.props,i=r.gql,s=r.refetchQueries,p=r.optimisticResponse,u=r.update,a=o.mutate({mutation:i,refetchQueries:s,optimisticResponse:p,update:u,variables:t});return this.setState({loading:!0}),a.then(function(t){e.mounted&&e.setState(Object.assign({},t,{error:null,loading:!1}))}).catch(function(t){e.mounted&&e.setState({error:t,loading:!1})}),a},e.prototype.render=function(){if(this.props.fail&&this.state.error)throw this.state.error;return(this.props.render||this.props.children)(this.mutate,this.state)},e}(r.Component);p.contextTypes={apollo:o.shape({client:o.object.isRequired}).isRequired},p.propTypes={gql:o.object.isRequired,variables:o.object,fail:o.bool,refetchQueries:o.array,optimisticResponse:o.func,update:o.func,children:o.func,render:o.func};var u=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){var t=this.props,e=t.client,o=t.queued,r=this.context.apollo;return r&&r.queued&&(o=r.queued),{apollo:{client:e,queued:o}}},e.prototype.render=function(){return this.props.children},e}(r.Component);u.contextTypes={apollo:o.shape({queued:o.array})},u.childContextTypes={apollo:o.shape({client:o.object.isRequired,queued:o.array}).isRequired};var a=function(t){this.mocks=t};a.prototype.mutate=function(t){return new Promise(function(t,e){return t()}.bind(this))},a.prototype.watchQuery=function(t){var e=this;return{refetch:function(t){return new Promise(function(t,e){return t()}.bind(e))},fetchMore:function(t){return new Promise(function(t,e){return t()}.bind(e))},setOptions:function(){},getLastResult:function(){},currentResult:function(){return{loading:!1,error:null,data:{}}},subscribe:function(t){t.next,t.error;return{unsubscribe:function(){}}}}};var c=function(t,o){if(void 0===o&&(o={}),Array.isArray(t))t.forEach(function(t){return t&&c(t,o)});else if("function"==typeof t.type){var r,n=o,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var p=new i(s,o);p.props=p.props||s,p.context=p.context||o,p.state=p.state||null,p.setState=function(t){"function"==typeof t&&(t=t(p.state,p.props,p.context)),p.state=Object.assign({},p.state,t)},p.componentWillMount&&p.componentWillMount(),p.getChildContext&&(n=Object.assign({},o,p.getChildContext())),r=p.render()}else r=i(s,o);Array.of(r).forEach(function(t){return t&&c(t,n)})}else t.props&&t.props.children&&e.Children.forEach(t.props.children,function(t){return t&&c(t,o)})};t.MockClient=a,t.Query=i,t.Mutate=p,t.Provider=u,t.renderState=function(t,o,r){void 0===r&&(r={});var n=r.maxDepth;void 0===n&&(n=1/0);var i=function(r){if(void 0===r&&(r=0),r<n){var s=[];c(e.createElement(u,{client:t,queued:s},o));var p=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(p.length)return Promise.all(p).then(function(){return i(r+1)})}return Promise.resolve()};return i()}});
//# sourceMappingURL=index.umd.js.map

@@ -1,2 +0,2 @@

function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t,e){for(var o in t)if(t[o]!==e[o])return!1;for(var r in e)if(!(r in t))return!1;return!0}function o(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}var r=require("react"),n=t(r),i=t(require("prop-types")),s=function(t){return"object"==typeof t&&t.constructor===Object},p=function(t){function r(e){t.call(this,e),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this),this.state={skipped:this.shouldSkip(e)}}return t&&(r.__proto__=t),r.prototype=Object.create(t&&t.prototype),r.prototype.constructor=r,r.prototype.componentWillMount=function(){var t=this.context.apollo||{},e=t.client,o=t.queued;if(!e)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");this.observable=e.watchQuery(u(this.props)),!this.props.lazy&&o&&o.push(this.observable)},r.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},r.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this.observable&&delete this.observable},r.prototype.componentWillReceiveProps=function(t,o){return t.gql!==this.props.gql?this.request(t):"boolean"==typeof t.skip&&t.skip!==this.props.skip?this.request(t):e(this.props.variables,t.variables)?void 0:this.request(t)},r.prototype.request=function(t){var e=this,r=this.shouldSkip(t);if(this.setState({skipped:r}),!r&&(this.observable.setOptions(u(t)),!this.subscription)){var n=o(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:n,error:n})}},r.prototype.shouldSkip=function(t){return"function"==typeof t.skip?!!t.skip(t.variables):"boolean"==typeof t.skip&&t.skip},r.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,o=t.error,r=this.state.skipped,n={};return o?Object.assign(n,(this.observable.getLastResult()||{}).data):Object.assign(n,this.previousData,t.data),this.previousData=n,{skipped:r,loading:e,error:o,data:n}},r.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable){var e=this.observable.refetch(s(t)?t:void 0);return this.props.wait||this.forceUpdate(),e}},r.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},r.prototype.render=function(){var t=this.getState();if(this.props.wait&&t.loading)return null;if(this.props.fail&&t.error)throw t.error;return(this.props.render||this.props.children)(Object.assign({},t,{refetch:this.refetch,fetchMore:this.fetchMore}))},r}(n.Component);p.contextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired},p.propTypes={gql:i.object.isRequired,variables:i.object,wait:i.bool,lazy:i.bool,skip:i.oneOfType([i.bool,i.func]),fail:i.bool,pollInterval:i.number,fetchPolicy:i.oneOf(["cache-first","cache-and-network","network-only","cache-only"]),errorPolicy:i.oneOf(["none","ignore","all"]),notifyOnNetworkStatusChange:i.bool,context:i.object,children:i.func,render:i.func};var u=function(t){return{query:t.gql,variables:t.variables,pollInterval:t.pollInterval,fetchPolicy:t.fetchPolicy,errorPolicy:t.errorPolicy,notifyOnNetworkStatusChange:t.notifyOnNetworkStatusChange,context:t.context}},c=function(t){function e(){t.call(this),this.mutate=this.mutate.bind(this),this.state={data:{},loading:!1}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentDidMount=function(){this.mounted=!0},e.prototype.componentWillUnmount=function(){this.mounted=!1},e.prototype.mutate=function(t){var e=this;s(t)||(t=void 0),void 0===t&&(t=this.props.variables);var o=this.context.apollo.client,r=this.props,n=r.gql,i=r.refetchQueries,p=r.optimisticResponse,u=r.update,c=o.mutate({mutation:n,refetchQueries:i,optimisticResponse:p,update:u,variables:t});return this.setState({loading:!0}),c.then(function(t){e.mounted&&e.setState(Object.assign({},t,{error:null,loading:!1}))}).catch(function(t){e.mounted&&e.setState({error:t,loading:!1})}),c},e.prototype.render=function(){if(this.props.fail&&this.state.error)throw this.state.error;return(this.props.render||this.props.children)(this.mutate,this.state)},e}(n.Component);c.contextTypes={apollo:i.shape({client:i.object.isRequired}).isRequired},c.propTypes={gql:i.object.isRequired,variables:i.object,fail:i.bool,refetchQueries:i.array,optimisticResponse:i.func,update:i.func,children:i.func,render:i.func};var a=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){var t=this.props,e=t.client,o=t.queued,r=this.context.apollo;return r&&r.queued&&(o=r.queued),{apollo:{client:e,queued:o}}},e.prototype.render=function(){return this.props.children},e}(n.Component);a.contextTypes={apollo:i.shape({queued:i.array})},a.childContextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired};var l=function(t){this.mocks=t};l.prototype.mutate=function(t){return new Promise(function(t,e){return t()}.bind(this))},l.prototype.watchQuery=function(t){var e=this;return{refetch:function(t){return new Promise(function(t,e){return t()}.bind(e))},fetchMore:function(t){return new Promise(function(t,e){return t()}.bind(e))},setOptions:function(){},getLastResult:function(){},currentResult:function(){return{loading:!1,error:null,data:{}}},subscribe:function(t){t.next,t.error;return{unsubscribe:function(){}}}}};var h=function(t,e,o){void 0===o&&(o={});var n=o.maxDepth;void 0===n&&(n=1/0);var i=function(o){if(void 0===o&&(o=0),o<n){var s=[];f(r.createElement(a,{client:t,queued:s},e));var p=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(p.length)return Promise.all(p).then(function(){return i(o+1)})}return Promise.resolve()};return i()},f=function(t,e){if(void 0===e&&(e={}),Array.isArray(t))t.forEach(function(t){return t&&f(t,e)});else if("function"==typeof t.type){var o,n=e,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var p=new i(s,e);p.props=p.props||s,p.context=p.context||e,p.state=p.state||null,p.setState=function(t){"function"==typeof t&&(t=t(p.state,p.props,p.context)),p.state=Object.assign({},p.state,t)},p.componentWillMount&&p.componentWillMount(),p.getChildContext&&(n=Object.assign({},e,p.getChildContext())),o=p.render()}else o=i(s,e);Array.of(o).forEach(function(t){return t&&f(t,n)})}else t.props&&t.props.children&&r.Children.forEach(t.props.children,function(t){return t&&f(t,e)})};exports.MockClient=l,exports.Query=p,exports.Mutate=c,exports.Provider=a,exports.renderState=h;
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t,e){for(var o in t)if(t[o]!==e[o])return!1;for(var r in e)if(!(r in t))return!1;return!0}function o(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}var r=require("react"),n=t(r),i=t(require("prop-types")),s=function(t){return"object"==typeof t&&t.constructor===Object},p=function(t){function r(e){t.call(this,e),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this),this.state={skipped:this.shouldSkip(e)}}t&&(r.__proto__=t),(r.prototype=Object.create(t&&t.prototype)).constructor=r;var n={observable:{configurable:!0}};return r.prototype.componentWillMount=function(){var t=(this.context.apollo||{}).queued;this.props.lazy||this.state.skipped||!t||t.push(this.observable)},r.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},r.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this._o&&delete this._o},r.prototype.componentWillReceiveProps=function(t,o){return t.gql!==this.props.gql?this.request(t):"boolean"==typeof t.skip&&t.skip!==this.props.skip?this.request(t):e(this.props.variables,t.variables)?void 0:this.request(t)},n.observable.get=function(){if(this._o)return this._o;var t=(this.context.apollo||{}).client;if(!t)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");return this._o=t.watchQuery(u(this.props))},r.prototype.request=function(t){var e=this,r=this.shouldSkip(t);if(this.setState({skipped:r}),!r&&(this.observable.setOptions(u(t)),!this.subscription)){var n=o(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:n,error:n})}},r.prototype.shouldSkip=function(t){return"function"==typeof t.skip?!!t.skip(t.variables):"boolean"==typeof t.skip&&t.skip},r.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,o=t.error,r=this.state.skipped,n={};return o?Object.assign(n,(this.observable.getLastResult()||{}).data):Object.assign(n,this.previousData,t.data),this.previousData=n,{skipped:r,loading:e,error:o,data:n}},r.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable){var e=this.observable.refetch(s(t)?t:void 0);return this.props.wait||this.forceUpdate(),e}},r.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},r.prototype.render=function(){var t=this.getState();if(this.props.wait&&t.loading)return null;if(this.props.fail&&t.error)throw t.error;return(this.props.render||this.props.children)(Object.assign({},t,{refetch:this.refetch,fetchMore:this.fetchMore}))},Object.defineProperties(r.prototype,n),r}(n.Component);p.contextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired},p.propTypes={gql:i.object.isRequired,variables:i.object,wait:i.bool,lazy:i.bool,skip:i.oneOfType([i.bool,i.func]),fail:i.bool,pollInterval:i.number,fetchPolicy:i.oneOf(["cache-first","cache-and-network","network-only","cache-only"]),errorPolicy:i.oneOf(["none","ignore","all"]),notifyOnNetworkStatusChange:i.bool,context:i.object,children:i.func,render:i.func};var u=function(t){return{query:t.gql,variables:t.variables,pollInterval:t.pollInterval,fetchPolicy:t.fetchPolicy,errorPolicy:t.errorPolicy,notifyOnNetworkStatusChange:t.notifyOnNetworkStatusChange,context:t.context}},c=function(t){function e(){t.call(this),this.mutate=this.mutate.bind(this),this.state={data:{},loading:!1}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentDidMount=function(){this.mounted=!0},e.prototype.componentWillUnmount=function(){this.mounted=!1},e.prototype.mutate=function(t){var e=this;s(t)||(t=void 0),void 0===t&&(t=this.props.variables);var o=this.context.apollo.client,r=this.props,n=r.gql,i=r.refetchQueries,p=r.optimisticResponse,u=r.update,c=o.mutate({mutation:n,refetchQueries:i,optimisticResponse:p,update:u,variables:t});return this.setState({loading:!0}),c.then(function(t){e.mounted&&e.setState(Object.assign({},t,{error:null,loading:!1}))}).catch(function(t){e.mounted&&e.setState({error:t,loading:!1})}),c},e.prototype.render=function(){if(this.props.fail&&this.state.error)throw this.state.error;return(this.props.render||this.props.children)(this.mutate,this.state)},e}(n.Component);c.contextTypes={apollo:i.shape({client:i.object.isRequired}).isRequired},c.propTypes={gql:i.object.isRequired,variables:i.object,fail:i.bool,refetchQueries:i.array,optimisticResponse:i.func,update:i.func,children:i.func,render:i.func};var a=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){var t=this.props,e=t.client,o=t.queued,r=this.context.apollo;return r&&r.queued&&(o=r.queued),{apollo:{client:e,queued:o}}},e.prototype.render=function(){return this.props.children},e}(n.Component);a.contextTypes={apollo:i.shape({queued:i.array})},a.childContextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired};var l=function(t){this.mocks=t};l.prototype.mutate=function(t){return new Promise(function(t,e){return t()}.bind(this))},l.prototype.watchQuery=function(t){var e=this;return{refetch:function(t){return new Promise(function(t,e){return t()}.bind(e))},fetchMore:function(t){return new Promise(function(t,e){return t()}.bind(e))},setOptions:function(){},getLastResult:function(){},currentResult:function(){return{loading:!1,error:null,data:{}}},subscribe:function(t){t.next,t.error;return{unsubscribe:function(){}}}}};var h=function(t,e,o){void 0===o&&(o={});var n=o.maxDepth;void 0===n&&(n=1/0);var i=function(o){if(void 0===o&&(o=0),o<n){var s=[];f(r.createElement(a,{client:t,queued:s},e));var p=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(p.length)return Promise.all(p).then(function(){return i(o+1)})}return Promise.resolve()};return i()},f=function(t,e){if(void 0===e&&(e={}),Array.isArray(t))t.forEach(function(t){return t&&f(t,e)});else if("function"==typeof t.type){var o,n=e,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var p=new i(s,e);p.props=p.props||s,p.context=p.context||e,p.state=p.state||null,p.setState=function(t){"function"==typeof t&&(t=t(p.state,p.props,p.context)),p.state=Object.assign({},p.state,t)},p.componentWillMount&&p.componentWillMount(),p.getChildContext&&(n=Object.assign({},e,p.getChildContext())),o=p.render()}else o=i(s,e);Array.of(o).forEach(function(t){return t&&f(t,n)})}else t.props&&t.props.children&&r.Children.forEach(t.props.children,function(t){return t&&f(t,e)})};exports.MockClient=l,exports.Query=p,exports.Mutate=c,exports.Provider=a,exports.renderState=h;
//# sourceMappingURL=mock.js.map
{
"name": "@department/apollo-component",
"version": "1.9.0",
"version": "1.9.1",
"description": "Render component for your Apollo Client",

@@ -5,0 +5,0 @@ "repository": "department-stockholm/apollo-component",

@@ -28,12 +28,6 @@ import React from "react";

componentWillMount() {
const { client, queued } = this.context.apollo || {};
if (!client) {
throw new Error(
"missing apollo client in context. is there a <Provider /> ancestor component?"
);
}
const { queued } = this.context.apollo || {};
this.observable = client.watchQuery(propsToOptions(this.props));
if (!this.props.lazy && queued) {
// skip rendering if no
if (!this.props.lazy && !this.state.skipped && queued) {
queued.push(this.observable);

@@ -56,4 +50,4 @@ }

if (this.observable) {
delete this.observable;
if (this._o) {
delete this._o;
}

@@ -77,2 +71,15 @@ }

get observable() {
if (this._o) {
return this._o;
}
const { client } = this.context.apollo || {};
if (!client) {
throw new Error(
"missing apollo client in context. is there a <Provider /> ancestor component?"
);
}
return (this._o = client.watchQuery(propsToOptions(this.props)));
}
request(props) {

@@ -79,0 +86,0 @@ const skipped = this.shouldSkip(props);

@@ -1,2 +0,2 @@

function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t,e){for(var o in t)if(t[o]!==e[o])return!1;for(var r in e)if(!(r in t))return!1;return!0}function o(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}var r=require("react"),n=t(r),i=t(require("prop-types")),s=function(t){return"object"==typeof t&&t.constructor===Object},p=function(t){function r(e){t.call(this,e),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this),this.state={skipped:this.shouldSkip(e)}}return t&&(r.__proto__=t),r.prototype=Object.create(t&&t.prototype),r.prototype.constructor=r,r.prototype.componentWillMount=function(){var t=this.context.apollo||{},e=t.client,o=t.queued;if(!e)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");this.observable=e.watchQuery(u(this.props)),!this.props.lazy&&o&&o.push(this.observable)},r.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},r.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this.observable&&delete this.observable},r.prototype.componentWillReceiveProps=function(t,o){return t.gql!==this.props.gql?this.request(t):"boolean"==typeof t.skip&&t.skip!==this.props.skip?this.request(t):e(this.props.variables,t.variables)?void 0:this.request(t)},r.prototype.request=function(t){var e=this,r=this.shouldSkip(t);if(this.setState({skipped:r}),!r&&(this.observable.setOptions(u(t)),!this.subscription)){var n=o(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:n,error:n})}},r.prototype.shouldSkip=function(t){return"function"==typeof t.skip?!!t.skip(t.variables):"boolean"==typeof t.skip&&t.skip},r.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,o=t.error,r=this.state.skipped,n={};return o?Object.assign(n,(this.observable.getLastResult()||{}).data):Object.assign(n,this.previousData,t.data),this.previousData=n,{skipped:r,loading:e,error:o,data:n}},r.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable){var e=this.observable.refetch(s(t)?t:void 0);return this.props.wait||this.forceUpdate(),e}},r.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},r.prototype.render=function(){var t=this.getState();if(this.props.wait&&t.loading)return null;if(this.props.fail&&t.error)throw t.error;return(this.props.render||this.props.children)(Object.assign({},t,{refetch:this.refetch,fetchMore:this.fetchMore}))},r}(n.Component);p.contextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired},p.propTypes={gql:i.object.isRequired,variables:i.object,wait:i.bool,lazy:i.bool,skip:i.oneOfType([i.bool,i.func]),fail:i.bool,pollInterval:i.number,fetchPolicy:i.oneOf(["cache-first","cache-and-network","network-only","cache-only"]),errorPolicy:i.oneOf(["none","ignore","all"]),notifyOnNetworkStatusChange:i.bool,context:i.object,children:i.func,render:i.func};var u=function(t){return{query:t.gql,variables:t.variables,pollInterval:t.pollInterval,fetchPolicy:t.fetchPolicy,errorPolicy:t.errorPolicy,notifyOnNetworkStatusChange:t.notifyOnNetworkStatusChange,context:t.context}},c=function(t){function e(){t.call(this),this.mutate=this.mutate.bind(this),this.state={data:{},loading:!1}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentDidMount=function(){this.mounted=!0},e.prototype.componentWillUnmount=function(){this.mounted=!1},e.prototype.mutate=function(t){var e=this;s(t)||(t=void 0),void 0===t&&(t=this.props.variables);var o=this.context.apollo.client,r=this.props,n=r.gql,i=r.refetchQueries,p=r.optimisticResponse,u=r.update,c=o.mutate({mutation:n,refetchQueries:i,optimisticResponse:p,update:u,variables:t});return this.setState({loading:!0}),c.then(function(t){e.mounted&&e.setState(Object.assign({},t,{error:null,loading:!1}))}).catch(function(t){e.mounted&&e.setState({error:t,loading:!1})}),c},e.prototype.render=function(){if(this.props.fail&&this.state.error)throw this.state.error;return(this.props.render||this.props.children)(this.mutate,this.state)},e}(n.Component);c.contextTypes={apollo:i.shape({client:i.object.isRequired}).isRequired},c.propTypes={gql:i.object.isRequired,variables:i.object,fail:i.bool,refetchQueries:i.array,optimisticResponse:i.func,update:i.func,children:i.func,render:i.func};var a=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){var t=this.props,e=t.client,o=t.queued,r=this.context.apollo;return r&&r.queued&&(o=r.queued),{apollo:{client:e,queued:o}}},e.prototype.render=function(){return this.props.children},e}(n.Component);a.contextTypes={apollo:i.shape({queued:i.array})},a.childContextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired};var l=function(t){this.mocks=t};l.prototype.mutate=function(t){return new Promise(function(t,e){return t()}.bind(this))},l.prototype.watchQuery=function(t){var e=this;return{refetch:function(t){return new Promise(function(t,e){return t()}.bind(e))},fetchMore:function(t){return new Promise(function(t,e){return t()}.bind(e))},setOptions:function(){},getLastResult:function(){},currentResult:function(){return{loading:!1,error:null,data:{}}},subscribe:function(t){t.next,t.error;return{unsubscribe:function(){}}}}};var h=function(t,e,o){void 0===o&&(o={});var n=o.maxDepth;void 0===n&&(n=1/0);var i=function(o){if(void 0===o&&(o=0),o<n){var s=[];f(r.createElement(a,{client:t,queued:s},e));var p=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(p.length)return Promise.all(p).then(function(){return i(o+1)})}return Promise.resolve()};return i()},f=function(t,e){if(void 0===e&&(e={}),Array.isArray(t))t.forEach(function(t){return t&&f(t,e)});else if("function"==typeof t.type){var o,n=e,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var p=new i(s,e);p.props=p.props||s,p.context=p.context||e,p.state=p.state||null,p.setState=function(t){"function"==typeof t&&(t=t(p.state,p.props,p.context)),p.state=Object.assign({},p.state,t)},p.componentWillMount&&p.componentWillMount(),p.getChildContext&&(n=Object.assign({},e,p.getChildContext())),o=p.render()}else o=i(s,e);Array.of(o).forEach(function(t){return t&&f(t,n)})}else t.props&&t.props.children&&r.Children.forEach(t.props.children,function(t){return t&&f(t,e)})};exports.MockClient=l,exports.Query=p,exports.Mutate=c,exports.Provider=a,exports.renderState=h;
function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t,e){for(var o in t)if(t[o]!==e[o])return!1;for(var r in e)if(!(r in t))return!1;return!0}function o(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}var r=require("react"),n=t(r),i=t(require("prop-types")),s=function(t){return"object"==typeof t&&t.constructor===Object},p=function(t){function r(e){t.call(this,e),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this),this.state={skipped:this.shouldSkip(e)}}t&&(r.__proto__=t),(r.prototype=Object.create(t&&t.prototype)).constructor=r;var n={observable:{configurable:!0}};return r.prototype.componentWillMount=function(){var t=(this.context.apollo||{}).queued;this.props.lazy||this.state.skipped||!t||t.push(this.observable)},r.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},r.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this._o&&delete this._o},r.prototype.componentWillReceiveProps=function(t,o){return t.gql!==this.props.gql?this.request(t):"boolean"==typeof t.skip&&t.skip!==this.props.skip?this.request(t):e(this.props.variables,t.variables)?void 0:this.request(t)},n.observable.get=function(){if(this._o)return this._o;var t=(this.context.apollo||{}).client;if(!t)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");return this._o=t.watchQuery(u(this.props))},r.prototype.request=function(t){var e=this,r=this.shouldSkip(t);if(this.setState({skipped:r}),!r&&(this.observable.setOptions(u(t)),!this.subscription)){var n=o(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:n,error:n})}},r.prototype.shouldSkip=function(t){return"function"==typeof t.skip?!!t.skip(t.variables):"boolean"==typeof t.skip&&t.skip},r.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,o=t.error,r=this.state.skipped,n={};return o?Object.assign(n,(this.observable.getLastResult()||{}).data):Object.assign(n,this.previousData,t.data),this.previousData=n,{skipped:r,loading:e,error:o,data:n}},r.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable){var e=this.observable.refetch(s(t)?t:void 0);return this.props.wait||this.forceUpdate(),e}},r.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},r.prototype.render=function(){var t=this.getState();if(this.props.wait&&t.loading)return null;if(this.props.fail&&t.error)throw t.error;return(this.props.render||this.props.children)(Object.assign({},t,{refetch:this.refetch,fetchMore:this.fetchMore}))},Object.defineProperties(r.prototype,n),r}(n.Component);p.contextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired},p.propTypes={gql:i.object.isRequired,variables:i.object,wait:i.bool,lazy:i.bool,skip:i.oneOfType([i.bool,i.func]),fail:i.bool,pollInterval:i.number,fetchPolicy:i.oneOf(["cache-first","cache-and-network","network-only","cache-only"]),errorPolicy:i.oneOf(["none","ignore","all"]),notifyOnNetworkStatusChange:i.bool,context:i.object,children:i.func,render:i.func};var u=function(t){return{query:t.gql,variables:t.variables,pollInterval:t.pollInterval,fetchPolicy:t.fetchPolicy,errorPolicy:t.errorPolicy,notifyOnNetworkStatusChange:t.notifyOnNetworkStatusChange,context:t.context}},c=function(t){function e(){t.call(this),this.mutate=this.mutate.bind(this),this.state={data:{},loading:!1}}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.componentDidMount=function(){this.mounted=!0},e.prototype.componentWillUnmount=function(){this.mounted=!1},e.prototype.mutate=function(t){var e=this;s(t)||(t=void 0),void 0===t&&(t=this.props.variables);var o=this.context.apollo.client,r=this.props,n=r.gql,i=r.refetchQueries,p=r.optimisticResponse,u=r.update,c=o.mutate({mutation:n,refetchQueries:i,optimisticResponse:p,update:u,variables:t});return this.setState({loading:!0}),c.then(function(t){e.mounted&&e.setState(Object.assign({},t,{error:null,loading:!1}))}).catch(function(t){e.mounted&&e.setState({error:t,loading:!1})}),c},e.prototype.render=function(){if(this.props.fail&&this.state.error)throw this.state.error;return(this.props.render||this.props.children)(this.mutate,this.state)},e}(n.Component);c.contextTypes={apollo:i.shape({client:i.object.isRequired}).isRequired},c.propTypes={gql:i.object.isRequired,variables:i.object,fail:i.bool,refetchQueries:i.array,optimisticResponse:i.func,update:i.func,children:i.func,render:i.func};var a=function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.getChildContext=function(){var t=this.props,e=t.client,o=t.queued,r=this.context.apollo;return r&&r.queued&&(o=r.queued),{apollo:{client:e,queued:o}}},e.prototype.render=function(){return this.props.children},e}(n.Component);a.contextTypes={apollo:i.shape({queued:i.array})},a.childContextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired};var l=function(t){this.mocks=t};l.prototype.mutate=function(t){return new Promise(function(t,e){return t()}.bind(this))},l.prototype.watchQuery=function(t){var e=this;return{refetch:function(t){return new Promise(function(t,e){return t()}.bind(e))},fetchMore:function(t){return new Promise(function(t,e){return t()}.bind(e))},setOptions:function(){},getLastResult:function(){},currentResult:function(){return{loading:!1,error:null,data:{}}},subscribe:function(t){t.next,t.error;return{unsubscribe:function(){}}}}};var h=function(t,e,o){void 0===o&&(o={});var n=o.maxDepth;void 0===n&&(n=1/0);var i=function(o){if(void 0===o&&(o=0),o<n){var s=[];f(r.createElement(a,{client:t,queued:s},e));var p=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(p.length)return Promise.all(p).then(function(){return i(o+1)})}return Promise.resolve()};return i()},f=function(t,e){if(void 0===e&&(e={}),Array.isArray(t))t.forEach(function(t){return t&&f(t,e)});else if("function"==typeof t.type){var o,n=e,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var p=new i(s,e);p.props=p.props||s,p.context=p.context||e,p.state=p.state||null,p.setState=function(t){"function"==typeof t&&(t=t(p.state,p.props,p.context)),p.state=Object.assign({},p.state,t)},p.componentWillMount&&p.componentWillMount(),p.getChildContext&&(n=Object.assign({},e,p.getChildContext())),o=p.render()}else o=i(s,e);Array.of(o).forEach(function(t){return t&&f(t,n)})}else t.props&&t.props.children&&r.Children.forEach(t.props.children,function(t){return t&&f(t,e)})};exports.MockClient=l,exports.Query=p,exports.Mutate=c,exports.Provider=a,exports.renderState=h;
//# sourceMappingURL=state.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc