chore: v3.0.0-beta.15

This commit is contained in:
Guillaume Chau
2018-05-28 12:27:29 +02:00
parent 086b57acd0
commit 87d4bba03e
4 changed files with 244 additions and 22 deletions
+119 -8
View File
@@ -1,5 +1,116 @@
import oThrottle from 'throttle-debounce/throttle';
import oDebounce from 'throttle-debounce/debounce';
/* eslint-disable no-undefined,no-param-reassign,no-shadow */
/**
* Throttle execution of a function. Especially useful for rate limiting
* execution of handlers on events like resize and scroll.
*
* @param {Number} delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param {Boolean} noTrailing Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the
* throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time
* after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,
* the internal counter is reset)
* @param {Function} callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the throttled-function is executed.
* @param {Boolean} debounceMode If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),
* schedule `callback` to execute after `delay` ms.
*
* @return {Function} A new, throttled, function.
*/
var throttle = function ( delay, noTrailing, callback, debounceMode ) {
// After wrapper has stopped being called, this timeout ensures that
// `callback` is executed at the proper times in `throttle` and `end`
// debounce modes.
var timeoutID;
// Keep track of the last time `callback` was executed.
var lastExec = 0;
// `noTrailing` defaults to falsy.
if ( typeof noTrailing !== 'boolean' ) {
debounceMode = callback;
callback = noTrailing;
noTrailing = undefined;
}
// The `wrapper` function encapsulates all of the throttling / debouncing
// functionality and when executed will limit the rate at which `callback`
// is executed.
function wrapper () {
var self = this;
var elapsed = Number(new Date()) - lastExec;
var args = arguments;
// Execute `callback` and update the `lastExec` timestamp.
function exec () {
lastExec = Number(new Date());
callback.apply(self, args);
}
// If `debounceMode` is true (at begin) this is used to clear the flag
// to allow future `callback` executions.
function clear () {
timeoutID = undefined;
}
if ( debounceMode && !timeoutID ) {
// Since `wrapper` is being called for the first time and
// `debounceMode` is true (at begin), execute `callback`.
exec();
}
// Clear any existing timeout.
if ( timeoutID ) {
clearTimeout(timeoutID);
}
if ( debounceMode === undefined && elapsed > delay ) {
// In throttle mode, if `delay` time has been exceeded, execute
// `callback`.
exec();
} else if ( noTrailing !== true ) {
// In trailing throttle mode, since `delay` time has not been
// exceeded, schedule `callback` to execute `delay` ms after most
// recent execution.
//
// If `debounceMode` is true (at begin), schedule `clear` to execute
// after `delay` ms.
//
// If `debounceMode` is false (at end), schedule `callback` to
// execute after `delay` ms.
timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay);
}
}
// Return the wrapper function.
return wrapper;
};
/* eslint-disable no-undefined */
/**
* Debounce execution of a function. Debouncing, unlike throttling,
* guarantees that a function is only executed a single time, either at the
* very beginning of a series of calls, or at the very end.
*
* @param {Number} delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param {Boolean} atBegin Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds
* after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.
* (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).
* @param {Function} callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the debounced-function is executed.
*
* @return {Function} A new, debounced function.
*/
var debounce = function ( delay, atBegin, callback ) {
return callback === undefined ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false);
};
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
@@ -205,9 +316,9 @@ function factory(action) {
};
}
var throttle = factory(oThrottle);
var throttle$2 = factory(throttle);
var debounce = factory(oDebounce);
var debounce$1 = factory(debounce);
function getMergedDefinition(def) {
return Globals.Vue.util.mergeOptions({}, def);
@@ -340,8 +451,8 @@ var SmartApollo = function () {
// GraphQL Variables
if (typeof this.options.variables === 'function') {
var _cb = this.executeApollo.bind(this);
_cb = this.options.throttle ? throttle(_cb, this.options.throttle) : _cb;
_cb = this.options.debounce ? debounce(_cb, this.options.debounce) : _cb;
_cb = this.options.throttle ? throttle$2(_cb, this.options.throttle) : _cb;
_cb = this.options.debounce ? debounce$1(_cb, this.options.debounce) : _cb;
this._watchers.push(this.vm.$watch(function () {
return _this.options.variables.call(_this.vm);
}, _cb, {
@@ -1709,7 +1820,7 @@ var CApolloMutation = {
var keywords = ['$subscribe'];
function hasProperty(holder, key) {
return typeof holder !== 'undefined' && holder.hasOwnProperty(key);
return typeof holder !== 'undefined' && Object.prototype.hasOwnProperty.call(holder, key);
}
function proxyData() {
@@ -1896,7 +2007,7 @@ function install(Vue, options) {
ApolloProvider.install = install;
// eslint-disable-next-line no-undef
ApolloProvider.version = "3.0.0-beta.14";
ApolloProvider.version = "3.0.0-beta.15";
// Apollo provider
var ApolloProvider$1 = ApolloProvider;
+1 -1
View File
File diff suppressed because one or more lines are too long
+123 -12
View File
@@ -1,11 +1,122 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('throttle-debounce/throttle'), require('throttle-debounce/debounce')) :
typeof define === 'function' && define.amd ? define(['exports', 'throttle-debounce/throttle', 'throttle-debounce/debounce'], factory) :
(factory((global['vue-apollo'] = {}),global.oThrottle,global.oDebounce));
}(this, (function (exports,oThrottle,oDebounce) { 'use strict';
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global['vue-apollo'] = {})));
}(this, (function (exports) { 'use strict';
oThrottle = oThrottle && oThrottle.hasOwnProperty('default') ? oThrottle['default'] : oThrottle;
oDebounce = oDebounce && oDebounce.hasOwnProperty('default') ? oDebounce['default'] : oDebounce;
/* eslint-disable no-undefined,no-param-reassign,no-shadow */
/**
* Throttle execution of a function. Especially useful for rate limiting
* execution of handlers on events like resize and scroll.
*
* @param {Number} delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param {Boolean} noTrailing Optional, defaults to false. If noTrailing is true, callback will only execute every `delay` milliseconds while the
* throttled-function is being called. If noTrailing is false or unspecified, callback will be executed one final time
* after the last throttled-function call. (After the throttled-function has not been called for `delay` milliseconds,
* the internal counter is reset)
* @param {Function} callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the throttled-function is executed.
* @param {Boolean} debounceMode If `debounceMode` is true (at begin), schedule `clear` to execute after `delay` ms. If `debounceMode` is false (at end),
* schedule `callback` to execute after `delay` ms.
*
* @return {Function} A new, throttled, function.
*/
var throttle = function ( delay, noTrailing, callback, debounceMode ) {
// After wrapper has stopped being called, this timeout ensures that
// `callback` is executed at the proper times in `throttle` and `end`
// debounce modes.
var timeoutID;
// Keep track of the last time `callback` was executed.
var lastExec = 0;
// `noTrailing` defaults to falsy.
if ( typeof noTrailing !== 'boolean' ) {
debounceMode = callback;
callback = noTrailing;
noTrailing = undefined;
}
// The `wrapper` function encapsulates all of the throttling / debouncing
// functionality and when executed will limit the rate at which `callback`
// is executed.
function wrapper () {
var self = this;
var elapsed = Number(new Date()) - lastExec;
var args = arguments;
// Execute `callback` and update the `lastExec` timestamp.
function exec () {
lastExec = Number(new Date());
callback.apply(self, args);
}
// If `debounceMode` is true (at begin) this is used to clear the flag
// to allow future `callback` executions.
function clear () {
timeoutID = undefined;
}
if ( debounceMode && !timeoutID ) {
// Since `wrapper` is being called for the first time and
// `debounceMode` is true (at begin), execute `callback`.
exec();
}
// Clear any existing timeout.
if ( timeoutID ) {
clearTimeout(timeoutID);
}
if ( debounceMode === undefined && elapsed > delay ) {
// In throttle mode, if `delay` time has been exceeded, execute
// `callback`.
exec();
} else if ( noTrailing !== true ) {
// In trailing throttle mode, since `delay` time has not been
// exceeded, schedule `callback` to execute `delay` ms after most
// recent execution.
//
// If `debounceMode` is true (at begin), schedule `clear` to execute
// after `delay` ms.
//
// If `debounceMode` is false (at end), schedule `callback` to
// execute after `delay` ms.
timeoutID = setTimeout(debounceMode ? clear : exec, debounceMode === undefined ? delay - elapsed : delay);
}
}
// Return the wrapper function.
return wrapper;
};
/* eslint-disable no-undefined */
/**
* Debounce execution of a function. Debouncing, unlike throttling,
* guarantees that a function is only executed a single time, either at the
* very beginning of a series of calls, or at the very end.
*
* @param {Number} delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param {Boolean} atBegin Optional, defaults to false. If atBegin is false or unspecified, callback will only be executed `delay` milliseconds
* after the last debounced-function call. If atBegin is true, callback will be executed only at the first debounced-function call.
* (After the throttled-function has not been called for `delay` milliseconds, the internal counter is reset).
* @param {Function} callback A function to be executed after delay milliseconds. The `this` context and all arguments are passed through, as-is,
* to `callback` when the debounced-function is executed.
*
* @return {Function} A new, debounced function.
*/
var debounce = function ( delay, atBegin, callback ) {
return callback === undefined ? throttle(delay, atBegin, false) : throttle(delay, callback, atBegin !== false);
};
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
@@ -211,9 +322,9 @@ function factory(action) {
};
}
var throttle = factory(oThrottle);
var throttle$2 = factory(throttle);
var debounce = factory(oDebounce);
var debounce$1 = factory(debounce);
function getMergedDefinition(def) {
return Globals.Vue.util.mergeOptions({}, def);
@@ -346,8 +457,8 @@ var SmartApollo = function () {
// GraphQL Variables
if (typeof this.options.variables === 'function') {
var _cb = this.executeApollo.bind(this);
_cb = this.options.throttle ? throttle(_cb, this.options.throttle) : _cb;
_cb = this.options.debounce ? debounce(_cb, this.options.debounce) : _cb;
_cb = this.options.throttle ? throttle$2(_cb, this.options.throttle) : _cb;
_cb = this.options.debounce ? debounce$1(_cb, this.options.debounce) : _cb;
this._watchers.push(this.vm.$watch(function () {
return _this.options.variables.call(_this.vm);
}, _cb, {
@@ -1715,7 +1826,7 @@ var CApolloMutation = {
var keywords = ['$subscribe'];
function hasProperty(holder, key) {
return typeof holder !== 'undefined' && holder.hasOwnProperty(key);
return typeof holder !== 'undefined' && Object.prototype.hasOwnProperty.call(holder, key);
}
function proxyData() {
@@ -1902,7 +2013,7 @@ function install(Vue, options) {
ApolloProvider.install = install;
// eslint-disable-next-line no-undef
ApolloProvider.version = "3.0.0-beta.14";
ApolloProvider.version = "3.0.0-beta.15";
// Apollo provider
var ApolloProvider$1 = ApolloProvider;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vue-apollo",
"version": "3.0.0-beta.14",
"version": "3.0.0-beta.15",
"description": "Use Apollo and GraphQL with Vue.js",
"main": "dist/vue-apollo.umd.js",
"module": "dist/vue-apollo.esm.js",