|
1 |
| -import oThrottle from 'throttle-debounce/throttle'; |
2 |
| -import oDebounce from 'throttle-debounce/debounce'; |
| 1 | +/* eslint-disable no-undefined,no-param-reassign,no-shadow */ |
| 2 | + |
| 3 | +/** |
| 4 | + * Throttle execution of a function. Especially useful for rate limiting |
| 5 | + * execution of handlers on events like resize and scroll. |
| 6 | + * |
| 7 | + * @param {Number} delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful. |
| 8 | + * @param {Boolean} noTrailing Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the |
| 9 | + * throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time |
| 10 | + * after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds, |
| 11 | + * the internal counter is reset) |
| 12 | + * @param {Function} callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is, |
| 13 | + * to `callback` when the throttled-function is executed. |
| 14 | + * @param {Boolean} debounceMode If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end), |
| 15 | + * schedule `callback` to execute after `delay` ms. |
| 16 | + * |
| 17 | + * @return {Function} A new, throttled, function. |
| 18 | + */ |
| 19 | +var throttle = function ( delay, noTrailing, callback, debounceMode ) { |
| 20 | + |
| 21 | + // After wrapper has stopped being called, this timeout ensures that |
| 22 | + // `callback` is executed at the proper times in `throttle` and `end` |
| 23 | + // debounce modes. |
| 24 | + var timeoutID; |
| 25 | + |
| 26 | + // Keep track of the last time `callback` was executed. |
| 27 | + var lastExec = 0; |
| 28 | + |
| 29 | + // `noTrailing` defaults to falsy. |
| 30 | + if ( typeof noTrailing !== 'boolean' ) { |
| 31 | + debounceMode = callback; |
| 32 | + callback = noTrailing; |
| 33 | + noTrailing = undefined; |
| 34 | + } |
| 35 | + |
| 36 | + // The `wrapper` function encapsulates all of the throttling / debouncing |
| 37 | + // functionality and when executed will limit the rate at which `callback` |
| 38 | + // is executed. |
| 39 | + function wrapper () { |
| 40 | + |
| 41 | + var self = this; |
| 42 | + var elapsed = Number(new Date()) - lastExec; |
| 43 | + var args = arguments; |
| 44 | + |
| 45 | + // Execute `callback` and update the `lastExec` timestamp. |
| 46 | + function exec () { |
| 47 | + lastExec = Number(new Date()); |
| 48 | + callback.apply(self, args); |
| 49 | + } |
| 50 | + |
| 51 | + // If `debounceMode` is true (at begin) this is used to clear the flag |
| 52 | + // to allow future `callback` executions. |
| 53 | + function clear () { |
| 54 | + timeoutID = undefined; |
| 55 | + } |
| 56 | + |
| 57 | + if ( debounceMode && !timeoutID ) { |
| 58 | + // Since `wrapper` is being called for the first time and |
| 59 | + // `debounceMode` is true (at begin), execute `callback`. |
| 60 | + exec(); |
| 61 | + } |
| 62 | + |
| 63 | + // Clear any existing timeout. |
| 64 | + if ( timeoutID ) { |
| 65 | + clearTimeout(timeoutID); |
| 66 | + } |
| 67 | + |
| 68 | + if ( debounceMode === undefined && elapsed > delay ) { |
| 69 | + // In throttle mode, if `delay` time has been exceeded, execute |
| 70 | + // `callback`. |
| 71 | + exec(); |
| 72 | + |
| 73 | + } else if ( noTrailing !== true ) { |
| 74 | + // In trailing throttle mode, since `delay` time has not been |
| 75 | + // exceeded, schedule `callback` to execute `delay` ms after most |
| 76 | + // recent execution. |
| 77 | + // |
| 78 | + // If `debounceMode` is true (at begin), schedule `clear` to execute |
| 79 | + // after `delay` ms. |
| 80 | + // |
| 81 | + // If `debounceMode` is false (at end), schedule `callback` to |
| 82 | + // execute after `delay` ms. |
| 83 | + timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay); |
| 84 | + } |
| 85 | + |
| 86 | + } |
| 87 | + |
| 88 | + // Return the wrapper function. |
| 89 | + return wrapper; |
| 90 | + |
| 91 | +}; |
| 92 | + |
| 93 | +/* eslint-disable no-undefined */ |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | +/** |
| 98 | + * Debounce execution of a function. Debouncing, unlike throttling, |
| 99 | + * guarantees that a function is only executed a single time, either at the |
| 100 | + * very beginning of a series of calls, or at the very end. |
| 101 | + * |
| 102 | + * @param {Number} delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful. |
| 103 | + * @param {Boolean} atBegin Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds |
| 104 | + * after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call. |
| 105 | + * (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset). |
| 106 | + * @param {Function} callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is, |
| 107 | + * to `callback` when the debounced-function is executed. |
| 108 | + * |
| 109 | + * @return {Function} A new, debounced function. |
| 110 | + */ |
| 111 | +var debounce = function ( delay, atBegin, callback ) { |
| 112 | + return callback === undefined ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false); |
| 113 | +}; |
3 | 114 |
|
4 | 115 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
5 | 116 | return typeof obj;
|
@@ -205,9 +316,9 @@ function factory(action) {
|
205 | 316 | };
|
206 | 317 | }
|
207 | 318 |
|
208 |
| -var throttle = factory(oThrottle); |
| 319 | +var throttle$2 = factory(throttle); |
209 | 320 |
|
210 |
| -var debounce = factory(oDebounce); |
| 321 | +var debounce$1 = factory(debounce); |
211 | 322 |
|
212 | 323 | function getMergedDefinition(def) {
|
213 | 324 | return Globals.Vue.util.mergeOptions({}, def);
|
@@ -340,8 +451,8 @@ var SmartApollo = function () {
|
340 | 451 | // GraphQL Variables
|
341 | 452 | if (typeof this.options.variables === 'function') {
|
342 | 453 | var _cb = this.executeApollo.bind(this);
|
343 |
| - _cb = this.options.throttle ? throttle(_cb, this.options.throttle) : _cb; |
344 |
| - _cb = this.options.debounce ? debounce(_cb, this.options.debounce) : _cb; |
| 454 | + _cb = this.options.throttle ? throttle$2(_cb, this.options.throttle) : _cb; |
| 455 | + _cb = this.options.debounce ? debounce$1(_cb, this.options.debounce) : _cb; |
345 | 456 | this._watchers.push(this.vm.$watch(function () {
|
346 | 457 | return _this.options.variables.call(_this.vm);
|
347 | 458 | }, _cb, {
|
@@ -1709,7 +1820,7 @@ var CApolloMutation = {
|
1709 | 1820 | var keywords = ['$subscribe'];
|
1710 | 1821 |
|
1711 | 1822 | function hasProperty(holder, key) {
|
1712 |
| - return typeof holder !== 'undefined' && holder.hasOwnProperty(key); |
| 1823 | + return typeof holder !== 'undefined' && Object.prototype.hasOwnProperty.call(holder, key); |
1713 | 1824 | }
|
1714 | 1825 |
|
1715 | 1826 | function proxyData() {
|
@@ -1896,7 +2007,7 @@ function install(Vue, options) {
|
1896 | 2007 | ApolloProvider.install = install;
|
1897 | 2008 |
|
1898 | 2009 | // eslint-disable-next-line no-undef
|
1899 |
| -ApolloProvider.version = "3.0.0-beta.14"; |
| 2010 | +ApolloProvider.version = "3.0.0-beta.15"; |
1900 | 2011 |
|
1901 | 2012 | // Apollo provider
|
1902 | 2013 | var ApolloProvider$1 = ApolloProvider;
|
|
0 commit comments