Skip to content

Commit 87d4bba

Browse files
author
Guillaume Chau
committed
chore: v3.0.0-beta.15
1 parent 086b57a commit 87d4bba

File tree

4 files changed

+244
-22
lines changed

4 files changed

+244
-22
lines changed

dist/vue-apollo.esm.js

+119-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,116 @@
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+
};
3114

4115
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
5116
return typeof obj;
@@ -205,9 +316,9 @@ function factory(action) {
205316
};
206317
}
207318

208-
var throttle = factory(oThrottle);
319+
var throttle$2 = factory(throttle);
209320

210-
var debounce = factory(oDebounce);
321+
var debounce$1 = factory(debounce);
211322

212323
function getMergedDefinition(def) {
213324
return Globals.Vue.util.mergeOptions({}, def);
@@ -340,8 +451,8 @@ var SmartApollo = function () {
340451
// GraphQL Variables
341452
if (typeof this.options.variables === 'function') {
342453
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;
345456
this._watchers.push(this.vm.$watch(function () {
346457
return _this.options.variables.call(_this.vm);
347458
}, _cb, {
@@ -1709,7 +1820,7 @@ var CApolloMutation = {
17091820
var keywords = ['$subscribe'];
17101821

17111822
function hasProperty(holder, key) {
1712-
return typeof holder !== 'undefined' && holder.hasOwnProperty(key);
1823+
return typeof holder !== 'undefined' && Object.prototype.hasOwnProperty.call(holder, key);
17131824
}
17141825

17151826
function proxyData() {
@@ -1896,7 +2007,7 @@ function install(Vue, options) {
18962007
ApolloProvider.install = install;
18972008

18982009
// eslint-disable-next-line no-undef
1899-
ApolloProvider.version = "3.0.0-beta.14";
2010+
ApolloProvider.version = "3.0.0-beta.15";
19002011

19012012
// Apollo provider
19022013
var ApolloProvider$1 = ApolloProvider;

0 commit comments

Comments
 (0)