本文整理汇总了TypeScript中lodash.debounce函数的典型用法代码示例。如果您正苦于以下问题:TypeScript debounce函数的具体用法?TypeScript debounce怎么用?TypeScript debounce使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了debounce函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
/**
* Constructor
*
* @param {ElementRef} elementRef
* @param {FuseConfigService} _fuseConfigService
* @param {Platform} _platform
* @param {Router} _router
*/
constructor(
public elementRef: ElementRef,
private _fuseConfigService: FuseConfigService,
private _platform: Platform,
private _router: Router
)
{
// Set the defaults
this.isInitialized = false;
this.isMobile = false;
// Set the private defaults
this._enabled = false;
this._debouncedUpdate = _.debounce(this.update, 150);
this._options = {
updateOnRouteChange: false
};
this._unsubscribeAll = new Subject();
}
示例2: constructor
constructor(vim: any, host: TypeScriptServerHost) {
this._vim = vim;
this._host = host;
this._updateHighlightFunction = _.debounce((file) => {
this._host._makeTssRequest<void>("navbar", {
file: file
}).then((val: any) => {
console.log("Got highlighting result: " + JSON.stringify(val));
var syntaxHighlighter = new SyntaxHighlighter();
var highlighting = syntaxHighlighter.getSyntaxHighlighting(val);
this._vim.setSyntaxHighlighting(highlighting);
console.log("Setting syntax highlighting: " + JSON.stringify(highlighting));
}, (err) => {
console.error(err);
});
}, 100);
}
示例3: data
export function createMixin<T extends object>(name: string, initialData: T) {
// @vue/component
return {
data() {
return {
displayState: _.cloneDeep(initialData)
};
},
watch: {
displayState: {
handler: _.debounce((value: any) => {
localStorage.setItem(name, JSON.stringify(value));
}, 500),
deep: true
}
},
mounted(this: { displayState: T }) {
let storedData: T | undefined;
const jsonString = localStorage.getItem(name);
if (jsonString) {
try {
storedData = JSON.parse(jsonString);
} catch (_) {
// leave storedData undefined
localStorage.removeItem(name);
}
}
const currentData = this.displayState;
if (storedData !== undefined) {
for (const key in currentData) {
const value = storedData[key];
if (value !== undefined) {
currentData[key] = value;
}
}
}
localStorage.setItem(name, JSON.stringify(currentData));
}
};
}
示例4: WatchExecutor
.flatMap(job => {
if (this._runner === undefined) {
const runner = new WatchExecutor(job, this._dialog);
this._runner = runner;
// FIXME how to stop the runner
const cbk = _.debounce(path => runner.run(), this._debounceTime);
this._watcher = chokidar.watch(this._def.files, {
// ignored: /../,
// persistent: true
});
this._watcher.on('error', err => {
console.error('Error during watch', err);
});
this._watcher.on('ready', () => {
LISTEN_EVENTS.forEach(eventName => this._watcher.on(eventName, cbk));
});
return runner.subject;
} else {
return this._runner.subject;
}
});
示例5: eventChannel
const resizeChan = eventChannel((emit) => {
artboard.mount.contentWindow.addEventListener("resize", debounce(emit, RESIZE_TIMEOUT));
return () => {};
});
示例6: function
link: function($scope, elem) {
const $input = $(inputTemplate);
const segment = $scope.segment;
const $button = $(segment.selectMode ? selectTemplate : linkTemplate);
let options = null;
let cancelBlur = null;
let linkMode = true;
const debounceLookup = $scope.debounce;
$input.appendTo(elem);
$button.appendTo(elem);
$scope.updateVariableValue = function(value) {
if (value === '' || segment.value === value) {
return;
}
value = _.unescape(value);
$scope.$apply(function() {
const selected = _.find($scope.altSegments, { value: value });
if (selected) {
segment.value = selected.value;
segment.html = selected.html || selected.value;
segment.fake = false;
segment.expandable = selected.expandable;
if (selected.type) {
segment.type = selected.type;
}
} else if (segment.custom !== 'false') {
segment.value = value;
segment.html = $sce.trustAsHtml(value);
segment.expandable = true;
segment.fake = false;
}
$scope.onChange();
});
};
$scope.switchToLink = function(fromClick) {
if (linkMode && !fromClick) {
return;
}
clearTimeout(cancelBlur);
cancelBlur = null;
linkMode = true;
$input.hide();
$button.show();
$scope.updateVariableValue($input.val());
};
$scope.inputBlur = function() {
// happens long before the click event on the typeahead options
// need to have long delay because the blur
cancelBlur = setTimeout($scope.switchToLink, 200);
};
$scope.source = function(query, callback) {
$scope.$apply(function() {
$scope.getOptions({ $query: query }).then(function(altSegments) {
$scope.altSegments = altSegments;
options = _.map($scope.altSegments, function(alt) {
return _.escape(alt.value);
});
// add custom values
if (segment.custom !== 'false') {
if (!segment.fake && _.indexOf(options, segment.value) === -1) {
options.unshift(segment.value);
}
}
callback(options);
});
});
};
$scope.updater = function(value) {
if (value === segment.value) {
clearTimeout(cancelBlur);
$input.focus();
return value;
}
$input.val(value);
$scope.switchToLink(true);
return value;
};
$scope.matcher = function(item) {
let str = this.query;
if (str[0] === '/') {
str = str.substring(1);
}
if (str[str.length - 1] === '/') {
str = str.substring(0, str.length - 1);
//.........这里部分代码省略.........
示例7: constructor
constructor(destination: Subscriber<T>, duration: number, options: DebounceOptions) {
super(destination);
this._duration = duration;
this._method = debounce(bind(this._dispatchNext, this), duration, options);
}
示例8: _saveWindowPosition
function _saveWindowPosition(sync: boolean, win: Electron.BrowserWindow) {
const size = win.getSize();
const pos = win.getPosition();
shellConfig.set("window.posX", pos[0]);
shellConfig.set("window.posY", pos[1]);
shellConfig.set("window.width", size[0]);
shellConfig.set("window.height", size[1]);
shellConfig.set("window.maximized", win.isMaximized());
if (sync) {
shellConfig.saveSync();
} else {
shellConfig.save();
}
}
const saveWindowPositionSync = _.partial(_saveWindowPosition, true);
const saveWindowPosition = _.debounce(_.partial(_saveWindowPosition, false), 100);
// Quit when all windows are closed.
let windowAllClosed = false;
app.on("window-all-closed", function () {
windowAllClosed = true;
setTimeout(app.quit, 500);
});
app.on("before-quit", function (event) {
if (!windowAllClosed) {
event.preventDefault();
const windows = BrowserWindow.getAllWindows();
windows.forEach((win) => win.close());
}
示例9: clearInterval
clearInterval(interval);
} else {
let goal;
if (scrollingDown) {
goal = Math.min(y, scrollTop + step);
} else {
goal = Math.max(y, scrollTop - step);
}
stepsDone++;
scrollTop = goal;
scrollElement(parent, goal);
}
}, SCROLLING_INTERVAL);
};
smoothScrollTop = debounce(smoothScrollTop, SCROLLING_DURATION, { leading: true });
export function scrollToElement(
element: Element,
options: {
topOffset?: number;
bottomOffset?: number;
parent?: Element;
smooth?: boolean;
}
): void {
const opts = { topOffset: 0, bottomOffset: 0, parent: window, smooth: true, ...options };
const { parent } = opts;
const { top, bottom } = element.getBoundingClientRect();
示例10: registerShortcuts
function registerShortcuts(menuItem: MenuItemOptions) {
if (menuItem.accelerator) {
if (null == systemShortcuts.find((x) => x === menuItem.accelerator)) {
globalShortcut.register(menuItem.accelerator, menuItem.click as Function);
}
}
if (Array.isArray(menuItem.submenu)) {
menuItem.submenu.forEach((i) => registerShortcuts(i));
}
}
const __refreshMenu = _.debounce(function () {
Menu.setApplicationMenu(Menu.buildFromTemplate(_.cloneDeep(menuTemplate)));
globalShortcut.unregisterAll();
const mainWindow = shell.getMainWindow();
if (mainWindow.isFocused()) {
menuTemplate.forEach((menuItem) => registerShortcuts(menuItem));
}
}, 100);
function _refreshMenu(callback?: () => void) {
__refreshMenu();
if (callback) {
process.nextTick(callback);
}
}
function _findMenuItemPosition(
id: string, where: MenuItemOptions[] = menuTemplate, whereId: string = ""
): [string, number] | null {
const result = _.find(where, { id });