Authored by ccbikai

前端移除 lodash

... ... @@ -10,13 +10,41 @@
const $ = require('yoho-jquery');
const Overlay = require('./overlay');
const template = require('components/loading.hbs');
const _ = require('lodash');
const AJAX_LOADING_ENABLED = false; // 全局控制
if (!Overlay) {
throw new Error('Required dependency "Overlay" not found!');
}
/**
* 创建一个无抖动的函数
* @param {[type]} func [description]
* @param {[type]} wait [description]
* @param {[type]} immediate [description]
* @return {[type]}
*/
function debounce(func, wait, immediate) {
let timeout;
return function() {
let context = this, args = arguments;
let later = function() {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
};
let callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
}
class Loading {
constructor(opts) {
this.defaults = {};
... ... @@ -63,13 +91,13 @@ const instance = new Loading();
if (AJAX_LOADING_ENABLED) {
$(document).ajaxStart(()=> {
_.debounce(()=> {
debounce(()=> {
instance.show();
}, 100)();
});
$(document).ajaxStop(()=> {
_.debounce(()=> {
debounce(()=> {
instance.hide();
}, 500)();
});
... ...