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.7.0 to 1.8.0

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

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

@@ -108,3 +108,11 @@ import React from "react";

// ex. <button onClick={refetch} />
return this.observable.refetch(isPlainObject(vars) ? vars : undefined);
const req = this.observable.refetch(
isPlainObject(vars) ? vars : undefined
);
// when not wait we trigger a render
// so that a loader can be shown
if (!this.props.wait) {
this.forceUpdate();
}
return req;
}

@@ -115,3 +123,9 @@ }

if (this.observable) {
return this.observable.fetchMore(opts);
const req = this.observable.fetchMore(opts);
// when not wait we trigger a render
// so that a loader can be shown
if (!this.props.wait) {
this.forceUpdate();
}
return req;
}

@@ -118,0 +132,0 @@ }

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

function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}function e(t,e){for(var r in t)if(t[r]!==e[r])return!1;for(var o in e)if(!(o in t))return!1;return!0}function r(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}var o=require("react"),n=t(o),i=t(require("prop-types")),s=function(t){return"object"==typeof t&&t.constructor===Object},u=function(t){function o(){t.call(this),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this)}return t&&(o.__proto__=t),o.prototype=Object.create(t&&t.prototype),o.prototype.constructor=o,o.prototype.componentWillMount=function(){var t=this.context.apollo||{},e=t.client,r=t.queued;if(!e)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");this.observable=e.watchQuery(c(this.props)),!this.props.lazy&&r&&r.push(this.observable)},o.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},o.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this.observable&&delete this.observable},o.prototype.componentWillReceiveProps=function(t,r){return t.gql!==this.props.gql?this.request(t):t.skip!==this.props.skip?this.request(t):e(this.props.variables,t.variables)?void 0:this.request(t)},o.prototype.request=function(t){var e=this;if(this.observable.setOptions(c(t)),!this.subscription){var o=r(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:o,error:o})}},o.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,r=t.error,o={};return r?Object.assign(o,(this.observable.getLastResult()||{}).data):Object.assign(o,this.previousData,t.data),this.previousData=o,{loading:e,error:r,data:o}},o.prototype.refetch=function(t){if(void 0===t&&(t=this.props.variables),this.observable)return this.observable.refetch(s(t)?t:void 0)},o.prototype.fetchMore=function(t){if(this.observable)return this.observable.fetchMore(t)},o.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}))},o}(n.Component);u.contextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired},u.propTypes={gql:i.object.isRequired,variables:i.object,wait:i.bool,lazy:i.bool,skip:i.bool,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 c=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;s(t)||(t=void 0),void 0===t&&(t=this.props.variables);var r=this.context.apollo.client,o=this.props,n=o.gql,i=o.refetchQueries,u=o.optimisticResponse,c=o.update,p=r.mutate({mutation:n,refetchQueries:i,optimisticResponse:u,update:c,variables:t});return this.setState({loading:!0}),p.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})}),p},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);p.contextTypes={apollo:i.shape({client:i.object.isRequired}).isRequired},p.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,r=t.queued,o=this.context.apollo;return o&&o.queued&&(r=o.queued),{apollo:{client:e,queued:r}}},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,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=[];f(o.createElement(a,{client:t,queued:s},e));var u=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(u.length)return Promise.all(u).then(function(){return i(r+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 r,n=e,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var u=new i(s,e);u.props=u.props||s,u.context=u.context||e,u.state=u.state||null,u.setState=function(t){"function"==typeof t&&(t=t(u.state,u.props,u.context)),u.state=Object.assign({},u.state,t)},u.componentWillMount&&u.componentWillMount(),u.getChildContext&&(n=Object.assign({},e,u.getChildContext())),r=u.render()}else r=i(s,e);Array.of(r).forEach(function(t){return t&&f(t,n)})}else t.props&&t.props.children&&o.Children.forEach(t.props.children,function(t){return t&&f(t,e)})};exports.MockClient=l,exports.Query=u,exports.Mutate=p,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 r in t)if(t[r]!==e[r])return!1;for(var o in e)if(!(o in t))return!1;return!0}function r(t){var e;return function(){cancelAnimationFrame(e),e=requestAnimationFrame(t.bind(null,arguments))}}var o=require("react"),n=t(o),i=t(require("prop-types")),s=function(t){return"object"==typeof t&&t.constructor===Object},u=function(t){function o(){t.call(this),this.refetch=this.refetch.bind(this),this.fetchMore=this.fetchMore.bind(this)}return t&&(o.__proto__=t),o.prototype=Object.create(t&&t.prototype),o.prototype.constructor=o,o.prototype.componentWillMount=function(){var t=this.context.apollo||{},e=t.client,r=t.queued;if(!e)throw new Error("missing apollo client in context. is there a <Provider /> ancestor component?");this.observable=e.watchQuery(c(this.props)),!this.props.lazy&&r&&r.push(this.observable)},o.prototype.componentDidMount=function(){this.mounted=!0,this.request(this.props)},o.prototype.componentWillUnmount=function(){this.mounted=!1,this.subscription&&(this.subscription.unsubscribe(),delete this.subscription),this.observable&&delete this.observable},o.prototype.componentWillReceiveProps=function(t,r){return t.gql!==this.props.gql?this.request(t):t.skip!==this.props.skip?this.request(t):e(this.props.variables,t.variables)?void 0:this.request(t)},o.prototype.request=function(t){var e=this;if(this.observable.setOptions(c(t)),!this.subscription){var o=r(function(){e.mounted&&e.forceUpdate()});this.subscription=this.observable.subscribe({next:o,error:o})}},o.prototype.getState=function(){var t=this.observable.currentResult(),e=t.loading,r=t.error,o={};return r?Object.assign(o,(this.observable.getLastResult()||{}).data):Object.assign(o,this.previousData,t.data),this.previousData=o,{loading:e,error:r,data:o}},o.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}},o.prototype.fetchMore=function(t){if(this.observable){var e=this.observable.fetchMore(t);return this.props.wait||this.forceUpdate(),e}},o.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}))},o}(n.Component);u.contextTypes={apollo:i.shape({client:i.object.isRequired,queued:i.array}).isRequired},u.propTypes={gql:i.object.isRequired,variables:i.object,wait:i.bool,lazy:i.bool,skip:i.bool,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 c=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;s(t)||(t=void 0),void 0===t&&(t=this.props.variables);var r=this.context.apollo.client,o=this.props,n=o.gql,i=o.refetchQueries,u=o.optimisticResponse,c=o.update,p=r.mutate({mutation:n,refetchQueries:i,optimisticResponse:u,update:c,variables:t});return this.setState({loading:!0}),p.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})}),p},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);p.contextTypes={apollo:i.shape({client:i.object.isRequired}).isRequired},p.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,r=t.queued,o=this.context.apollo;return o&&o.queued&&(r=o.queued),{apollo:{client:e,queued:r}}},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,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=[];f(o.createElement(a,{client:t,queued:s},e));var u=s.filter(function(t){return t.currentResult().loading}).map(function(t){return t.result()});if(u.length)return Promise.all(u).then(function(){return i(r+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 r,n=e,i=t.type,s=Object.assign({},i.defaultProps,t.props);if(i.prototype&&i.prototype.isReactComponent){var u=new i(s,e);u.props=u.props||s,u.context=u.context||e,u.state=u.state||null,u.setState=function(t){"function"==typeof t&&(t=t(u.state,u.props,u.context)),u.state=Object.assign({},u.state,t)},u.componentWillMount&&u.componentWillMount(),u.getChildContext&&(n=Object.assign({},e,u.getChildContext())),r=u.render()}else r=i(s,e);Array.of(r).forEach(function(t){return t&&f(t,n)})}else t.props&&t.props.children&&o.Children.forEach(t.props.children,function(t){return t&&f(t,e)})};exports.MockClient=l,exports.Query=u,exports.Mutate=p,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