diff --git a/dist/vue-apollo.esm.js b/dist/vue-apollo.esm.js index b794f8ad..552bf216 100644 --- a/dist/vue-apollo.esm.js +++ b/dist/vue-apollo.esm.js @@ -2961,9 +2961,15 @@ var SmartSubscription = function (_SmartApollo2) { createClass(SmartSubscription, [{ key: 'executeApollo', value: function executeApollo(variables) { + var variablesJson = JSON.stringify(variables); if (this.sub) { + // do nothing if subscription is already running using exactly the same variables + if (variablesJson === this.previousVariablesJson) { + return; + } this.sub.unsubscribe(); } + this.previousVariablesJson = variablesJson; var apolloOptions = this.generateApolloOptions(variables); diff --git a/dist/vue-apollo.min.js b/dist/vue-apollo.min.js index d4d8620b..7ef705c0 100644 --- a/dist/vue-apollo.min.js +++ b/dist/vue-apollo.min.js @@ -1 +1 @@ -!function(t){"use strict";function e(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}function r(t,e){var r=t?t.length:0;return!!r&&a(t,e,0)>-1}function i(t,e,r){for(var i=-1,n=t?t.length:0;++i-1}function S(t,e){var r=this.__data__,i=K(r,t);return i<0?r.push([t,e]):r[i][1]=e,this}function A(t){var e=-1,r=t?t.length:0;for(this.clear();++e=Qt&&(u=f,l=!1,e=new T(e));t:for(;++a0&&r(u)?e>1?R(u,e-1,r,i,n):o(n,u):i||(n[n.length]=u)}return n}function D(t,e,r){var i=e(t);return he(t)?i:o(i,r(t))}function N(t){if(!lt(t)||Y(t))return!1;var e=at(t)||p(t)?te:Nt;return e.test(rt(t))}function I(t){if(!lt(t))return tt(t);var e=Z(t),r=[];for(var i in t)("constructor"!=i||!e&&Yt.call(t,i))&&r.push(i);return r}function F(t,e){return t=Object(t),H(t,e,function(e,r){return r in t})}function H(t,e,r){for(var i=-1,n=e.length,o={};++i-1&&t%1==0&&t-1&&t%1==0&&t<=qt}function lt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function ct(t){return!!t&&"object"==typeof t}function ft(t){return"symbol"==typeof t||ct(t)&&Zt.call(t)==Rt}function ht(t){return ot(t)?C(t,!0):I(t)}function pt(){return[]}function vt(t,e,r){function i(e){var r=h,i=p;return h=p=void 0,g=e,y=t.apply(i,r)}function n(t){return g=t,d=setTimeout(a,e),_?i(t):y}function o(t){var r=t-b,i=t-g,n=e-r;return m?xe(n,v-i):n}function s(t){var r=t-b,i=t-g;return void 0===b||r>=e||r<0||m&&i>=v}function a(){var t=Ee();return s(t)?u(t):void(d=setTimeout(a,o(t)))}function u(t){return d=void 0,w&&h?i(t):(h=p=void 0,y)}function l(){void 0!==d&&clearTimeout(d),g=0,h=b=p=d=void 0}function c(){return void 0===d?y:u(Ee())}function f(){var t=Ee(),r=s(t);if(h=arguments,p=this,b=t,r){if(void 0===d)return n(b);if(m)return d=setTimeout(a,e),i(b)}return void 0===d&&(d=setTimeout(a,e)),y}var h,p,v,y,d,b,g=0,_=!1,m=!1,w=!0;if("function"!=typeof t)throw new TypeError(ye);return e=_t(e)||0,dt(r)&&(_=!!r.leading,m="maxWait"in r,v=m?Pe(_t(r.maxWait)||0,e):v,w="trailing"in r?!!r.trailing:w),f.cancel=l,f.flush=c,f}function yt(t,e,r){var i=!0,n=!0;if("function"!=typeof t)throw new TypeError(ye);return dt(r)&&(i="leading"in r?!!r.leading:i,n="trailing"in r?!!r.trailing:n),vt(t,e,{leading:i,maxWait:e,trailing:n})}function dt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function bt(t){return!!t&&"object"==typeof t}function gt(t){return"symbol"==typeof t||bt(t)&&Ae.call(t)==be}function _t(t){if("number"==typeof t)return t;if(gt(t))return de;if(dt(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=dt(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(ge,"");var r=me.test(t);return r||we.test(t)?ke(t.slice(2),r?2:8):_e.test(t)?de:+t}function mt(t,e,r){function i(e){var r=h,i=p;return h=p=void 0,g=e,y=t.apply(i,r)}function n(t){return g=t,d=setTimeout(a,e),_?i(t):y}function o(t){var r=t-b,i=t-g,n=e-r;return m?Ge(n,v-i):n}function s(t){var r=t-b,i=t-g;return void 0===b||r>=e||r<0||m&&i>=v}function a(){var t=Je();return s(t)?u(t):void(d=setTimeout(a,o(t)))}function u(t){return d=void 0,w&&h?i(t):(h=p=void 0,y)}function l(){void 0!==d&&clearTimeout(d),g=0,h=b=p=d=void 0}function c(){return void 0===d?y:u(Je())}function f(){var t=Je(),r=s(t);if(h=arguments,p=this,b=t,r){if(void 0===d)return n(b);if(m)return d=setTimeout(a,e),i(b)}return void 0===d&&(d=setTimeout(a,e)),y}var h,p,v,y,d,b,g=0,_=!1,m=!1,w=!0;if("function"!=typeof t)throw new TypeError(Qe);return e=jt(e)||0,wt(r)&&(_=!!r.leading,m="maxWait"in r,v=m?We(jt(r.maxWait)||0,e):v,w="trailing"in r?!!r.trailing:w),f.cancel=l,f.flush=c,f}function wt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function kt(t){return!!t&&"object"==typeof t}function Ot(t){return"symbol"==typeof t||kt(t)&&He.call(t)==Me}function jt(t){if("number"==typeof t)return t;if(Ot(t))return Te;if(wt(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=wt(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(qe,"");var r=Ke.test(t);return r||Ve.test(t)?Re(t.slice(2),r?2:8):Ce.test(t)?Te:+t}function $t(t){return function(e,r){return"number"==typeof r?t(e,r):t(e,r.wait,r)}}function St(t){return ze.Vue.util.mergeOptions({},t)}function At(t,e){for(;"function"==typeof t;)t=t.call(e);return t}function Pt(t){return pr.push(t),t}function xt(t,e,r){"undefined"!=typeof r&&("function"==typeof r?t.defineReactiveSetter(e,r):t[e]=r)}function Et(t,e){if(!Et.installed){Et.installed=!0,ze.Vue=t;var r=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,i){if(!t)return e;if(!e)return t;for(var n=Object.assign({},ve(t,vr),t.data),o=Object.assign({},ve(e,vr),e.data),s={},a=0;a3&&void 0!==arguments[3])||arguments[3];if(tr(this,t),this.type=null,this.vueApolloSpecialKeys=[],this.vm=e,this.key=r,this.options=Object.assign({},i),this._skip=!1,this._watchers=[],"function"==typeof this.options.query){var s=this.options.query.bind(this.vm);this.options.query=s(),this._watchers.push(this.vm.$watch(s,function(t){n.options.query=t,n.refresh()}))}if("function"==typeof this.options.document){var a=this.options.document.bind(this.vm);this.options.document=a(),this._watchers.push(this.vm.$watch(a,function(t){n.options.document=t,n.refresh()}))}o&&this.autostart()}return er(t,[{key:"autostart",value:function(){"function"==typeof this.options.skip?this._watchers.push(this.vm.$watch(this.options.skip.bind(this.vm),this.skipChanged.bind(this),{immediate:!0})):this.options.skip?this._skip=!0:this.start()}},{key:"skipChanged",value:function(t,e){t!==e&&(this.skip=t)}},{key:"refresh",value:function(){this._skip||(this.stop(),this.start())}},{key:"start",value:function(){var t=this;if(this.starting=!0,"function"==typeof this.options.variables){var e=this.executeApollo.bind(this);e=this.options.throttle?Be(e,this.options.throttle):e,e=this.options.debounce?Xe(e,this.options.debounce):e,this.unwatchVariables=this.vm.$watch(function(){return t.options.variables.call(t.vm)},e,{immediate:!0})}else this.executeApollo(this.options.variables)}},{key:"stop",value:function(){this.unwatchVariables&&(this.unwatchVariables(),this.unwatchVariables=null),this.sub&&(this.sub.unsubscribe(),this.sub=null)}},{key:"generateApolloOptions",value:function(t){var e=ve(this.options,this.vueApolloSpecialKeys);return e.variables=t,e}},{key:"executeApollo",value:function(t){this.starting=!1}},{key:"nextResult",value:function(){throw new Error("Not implemented")}},{key:"errorHandler",value:function(){for(var t,e,r,i=arguments.length,n=Array(i),o=0;o3&&void 0!==arguments[3])||arguments[3];if(tr(this,e),!i.query){var o=i;i={query:o}}var s=sr(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r,i,n));return s.type="query",s.vueApolloSpecialKeys=Ye,s.loading=!1,s}return or(e,t),er(e,[{key:"stop",value:function(){nr(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"stop",this).call(this),this.observer&&(this.observer.stopPolling(),this.observer=null)}},{key:"executeApollo",value:function(t){this.observer?this.observer.setOptions(this.generateApolloOptions(t)):(this.sub&&this.sub.unsubscribe(),this.observer=this.vm.$apollo.watchQuery(this.generateApolloOptions(t)),this.sub=this.observer.subscribe({next:this.nextResult.bind(this),error:this.catchError.bind(this)})),this.maySetLoading(),nr(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"executeApollo",this).call(this,t)}},{key:"maySetLoading",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.observer.currentResult();(t||e.loading)&&(this.loading||this.applyLoadingModifier(1),this.loading=!0)}},{key:"nextResult",value:function(t){var e=t.data,r=t.loading;r||this.loadingDone(),"undefined"==typeof e||("function"==typeof this.options.update?this.vm[this.key]=this.options.update.call(this.vm,e):void 0===e[this.key]?console.error("Missing "+this.key+" attribute on result",e):this.vm[this.key]=e[this.key]),"function"==typeof this.options.result&&this.options.result.call(this.vm,t)}},{key:"catchError",value:function(t){nr(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"catchError",this).call(this,t),this.loadingDone()}},{key:"watchLoading",value:function(){for(var t,e,r,i=arguments.length,n=Array(i),o=0;o `subscribe` option is deprecated. Use the `$subscribe` option instead."),t.$subscribe))for(var r in t.$subscribe)this.$apollo.addSmartSubscription(r,t.$subscribe[r])}};hr.install=Et;var br=hr,gr=null;"undefined"!=typeof window?gr=window.Vue:"undefined"!=typeof global&&(gr=global.Vue),gr&&gr.use(hr),t.install=Et,t.ApolloProvider=br,t.default=hr,t.willPrefetch=Pt}(this.VueApollo=this.VueApollo||{}); +!function(t){"use strict";function e(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}function r(t,e){var r=t?t.length:0;return!!r&&a(t,e,0)>-1}function i(t,e,r){for(var i=-1,n=t?t.length:0;++i-1}function S(t,e){var r=this.__data__,i=V(r,t);return i<0?r.push([t,e]):r[i][1]=e,this}function A(t){var e=-1,r=t?t.length:0;for(this.clear();++e=Qt&&(u=f,l=!1,e=new T(e));t:for(;++a0&&r(u)?e>1?R(u,e-1,r,i,n):o(n,u):i||(n[n.length]=u)}return n}function D(t,e,r){var i=e(t);return he(t)?i:o(i,r(t))}function N(t){if(!lt(t)||Y(t))return!1;var e=at(t)||p(t)?te:Nt;return e.test(rt(t))}function I(t){if(!lt(t))return tt(t);var e=Z(t),r=[];for(var i in t)("constructor"!=i||!e&&Yt.call(t,i))&&r.push(i);return r}function F(t,e){return t=Object(t),H(t,e,function(e,r){return r in t})}function H(t,e,r){for(var i=-1,n=e.length,o={};++i-1&&t%1==0&&t-1&&t%1==0&&t<=qt}function lt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function ct(t){return!!t&&"object"==typeof t}function ft(t){return"symbol"==typeof t||ct(t)&&Zt.call(t)==Rt}function ht(t){return ot(t)?C(t,!0):I(t)}function pt(){return[]}function vt(t,e,r){function i(e){var r=h,i=p;return h=p=void 0,g=e,y=t.apply(i,r)}function n(t){return g=t,d=setTimeout(a,e),_?i(t):y}function o(t){var r=t-b,i=t-g,n=e-r;return m?xe(n,v-i):n}function s(t){var r=t-b,i=t-g;return void 0===b||r>=e||r<0||m&&i>=v}function a(){var t=Ee();return s(t)?u(t):void(d=setTimeout(a,o(t)))}function u(t){return d=void 0,w&&h?i(t):(h=p=void 0,y)}function l(){void 0!==d&&clearTimeout(d),g=0,h=b=p=d=void 0}function c(){return void 0===d?y:u(Ee())}function f(){var t=Ee(),r=s(t);if(h=arguments,p=this,b=t,r){if(void 0===d)return n(b);if(m)return d=setTimeout(a,e),i(b)}return void 0===d&&(d=setTimeout(a,e)),y}var h,p,v,y,d,b,g=0,_=!1,m=!1,w=!0;if("function"!=typeof t)throw new TypeError(ye);return e=_t(e)||0,dt(r)&&(_=!!r.leading,m="maxWait"in r,v=m?Pe(_t(r.maxWait)||0,e):v,w="trailing"in r?!!r.trailing:w),f.cancel=l,f.flush=c,f}function yt(t,e,r){var i=!0,n=!0;if("function"!=typeof t)throw new TypeError(ye);return dt(r)&&(i="leading"in r?!!r.leading:i,n="trailing"in r?!!r.trailing:n),vt(t,e,{leading:i,maxWait:e,trailing:n})}function dt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function bt(t){return!!t&&"object"==typeof t}function gt(t){return"symbol"==typeof t||bt(t)&&Ae.call(t)==be}function _t(t){if("number"==typeof t)return t;if(gt(t))return de;if(dt(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=dt(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(ge,"");var r=me.test(t);return r||we.test(t)?ke(t.slice(2),r?2:8):_e.test(t)?de:+t}function mt(t,e,r){function i(e){var r=h,i=p;return h=p=void 0,g=e,y=t.apply(i,r)}function n(t){return g=t,d=setTimeout(a,e),_?i(t):y}function o(t){var r=t-b,i=t-g,n=e-r;return m?Ge(n,v-i):n}function s(t){var r=t-b,i=t-g;return void 0===b||r>=e||r<0||m&&i>=v}function a(){var t=Je();return s(t)?u(t):void(d=setTimeout(a,o(t)))}function u(t){return d=void 0,w&&h?i(t):(h=p=void 0,y)}function l(){void 0!==d&&clearTimeout(d),g=0,h=b=p=d=void 0}function c(){return void 0===d?y:u(Je())}function f(){var t=Je(),r=s(t);if(h=arguments,p=this,b=t,r){if(void 0===d)return n(b);if(m)return d=setTimeout(a,e),i(b)}return void 0===d&&(d=setTimeout(a,e)),y}var h,p,v,y,d,b,g=0,_=!1,m=!1,w=!0;if("function"!=typeof t)throw new TypeError(Qe);return e=jt(e)||0,wt(r)&&(_=!!r.leading,m="maxWait"in r,v=m?We(jt(r.maxWait)||0,e):v,w="trailing"in r?!!r.trailing:w),f.cancel=l,f.flush=c,f}function wt(t){var e=typeof t;return!!t&&("object"==e||"function"==e)}function kt(t){return!!t&&"object"==typeof t}function Ot(t){return"symbol"==typeof t||kt(t)&&He.call(t)==Me}function jt(t){if("number"==typeof t)return t;if(Ot(t))return Te;if(wt(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=wt(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=t.replace(qe,"");var r=Ve.test(t);return r||Ke.test(t)?Re(t.slice(2),r?2:8):Ce.test(t)?Te:+t}function $t(t){return function(e,r){return"number"==typeof r?t(e,r):t(e,r.wait,r)}}function St(t){return ze.Vue.util.mergeOptions({},t)}function At(t,e){for(;"function"==typeof t;)t=t.call(e);return t}function Pt(t){return pr.push(t),t}function xt(t,e,r){"undefined"!=typeof r&&("function"==typeof r?t.defineReactiveSetter(e,r):t[e]=r)}function Et(t,e){if(!Et.installed){Et.installed=!0,ze.Vue=t;var r=t.config.optionMergeStrategies.methods;t.config.optionMergeStrategies.apollo=function(t,e,i){if(!t)return e;if(!e)return t;for(var n=Object.assign({},ve(t,vr),t.data),o=Object.assign({},ve(e,vr),e.data),s={},a=0;a3&&void 0!==arguments[3])||arguments[3];if(tr(this,t),this.type=null,this.vueApolloSpecialKeys=[],this.vm=e,this.key=r,this.options=Object.assign({},i),this._skip=!1,this._watchers=[],"function"==typeof this.options.query){var s=this.options.query.bind(this.vm);this.options.query=s(),this._watchers.push(this.vm.$watch(s,function(t){n.options.query=t,n.refresh()}))}if("function"==typeof this.options.document){var a=this.options.document.bind(this.vm);this.options.document=a(),this._watchers.push(this.vm.$watch(a,function(t){n.options.document=t,n.refresh()}))}o&&this.autostart()}return er(t,[{key:"autostart",value:function(){"function"==typeof this.options.skip?this._watchers.push(this.vm.$watch(this.options.skip.bind(this.vm),this.skipChanged.bind(this),{immediate:!0})):this.options.skip?this._skip=!0:this.start()}},{key:"skipChanged",value:function(t,e){t!==e&&(this.skip=t)}},{key:"refresh",value:function(){this._skip||(this.stop(),this.start())}},{key:"start",value:function(){var t=this;if(this.starting=!0,"function"==typeof this.options.variables){var e=this.executeApollo.bind(this);e=this.options.throttle?Be(e,this.options.throttle):e,e=this.options.debounce?Xe(e,this.options.debounce):e,this.unwatchVariables=this.vm.$watch(function(){return t.options.variables.call(t.vm)},e,{immediate:!0})}else this.executeApollo(this.options.variables)}},{key:"stop",value:function(){this.unwatchVariables&&(this.unwatchVariables(),this.unwatchVariables=null),this.sub&&(this.sub.unsubscribe(),this.sub=null)}},{key:"generateApolloOptions",value:function(t){var e=ve(this.options,this.vueApolloSpecialKeys);return e.variables=t,e}},{key:"executeApollo",value:function(t){this.starting=!1}},{key:"nextResult",value:function(){throw new Error("Not implemented")}},{key:"errorHandler",value:function(){for(var t,e,r,i=arguments.length,n=Array(i),o=0;o3&&void 0!==arguments[3])||arguments[3];if(tr(this,e),!i.query){var o=i;i={query:o}}var s=sr(this,(e.__proto__||Object.getPrototypeOf(e)).call(this,t,r,i,n));return s.type="query",s.vueApolloSpecialKeys=Ye,s.loading=!1,s}return or(e,t),er(e,[{key:"stop",value:function(){nr(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"stop",this).call(this),this.observer&&(this.observer.stopPolling(),this.observer=null)}},{key:"executeApollo",value:function(t){this.observer?this.observer.setOptions(this.generateApolloOptions(t)):(this.sub&&this.sub.unsubscribe(),this.observer=this.vm.$apollo.watchQuery(this.generateApolloOptions(t)),this.sub=this.observer.subscribe({next:this.nextResult.bind(this),error:this.catchError.bind(this)})),this.maySetLoading(),nr(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"executeApollo",this).call(this,t)}},{key:"maySetLoading",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=this.observer.currentResult();(t||e.loading)&&(this.loading||this.applyLoadingModifier(1),this.loading=!0)}},{key:"nextResult",value:function(t){var e=t.data,r=t.loading;r||this.loadingDone(),"undefined"==typeof e||("function"==typeof this.options.update?this.vm[this.key]=this.options.update.call(this.vm,e):void 0===e[this.key]?console.error("Missing "+this.key+" attribute on result",e):this.vm[this.key]=e[this.key]),"function"==typeof this.options.result&&this.options.result.call(this.vm,t)}},{key:"catchError",value:function(t){nr(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"catchError",this).call(this,t),this.loadingDone()}},{key:"watchLoading",value:function(){for(var t,e,r,i=arguments.length,n=Array(i),o=0;o `subscribe` option is deprecated. Use the `$subscribe` option instead."),t.$subscribe))for(var r in t.$subscribe)this.$apollo.addSmartSubscription(r,t.$subscribe[r])}};hr.install=Et;var br=hr,gr=null;"undefined"!=typeof window?gr=window.Vue:"undefined"!=typeof global&&(gr=global.Vue),gr&&gr.use(hr),t.install=Et,t.ApolloProvider=br,t.default=hr,t.willPrefetch=Pt}(this.VueApollo=this.VueApollo||{}); diff --git a/dist/vue-apollo.umd.js b/dist/vue-apollo.umd.js index 85ffcdc6..149d7914 100644 --- a/dist/vue-apollo.umd.js +++ b/dist/vue-apollo.umd.js @@ -2967,9 +2967,15 @@ var SmartSubscription = function (_SmartApollo2) { createClass(SmartSubscription, [{ key: 'executeApollo', value: function executeApollo(variables) { + var variablesJson = JSON.stringify(variables); if (this.sub) { + // do nothing if subscription is already running using exactly the same variables + if (variablesJson === this.previousVariablesJson) { + return; + } this.sub.unsubscribe(); } + this.previousVariablesJson = variablesJson; var apolloOptions = this.generateApolloOptions(variables); diff --git a/src/smart-apollo.js b/src/smart-apollo.js index b579dd84..40c98dec 100644 --- a/src/smart-apollo.js +++ b/src/smart-apollo.js @@ -340,9 +340,15 @@ export class SmartSubscription extends SmartApollo { ] executeApollo (variables) { + const variablesJson = JSON.stringify(variables) if (this.sub) { + // do nothing if subscription is already running using exactly the same variables + if (variablesJson === this.previousVariablesJson) { + return + } this.sub.unsubscribe() } + this.previousVariablesJson = variablesJson const apolloOptions = this.generateApolloOptions(variables)