Kaynağa Gözat

Fixes tracked debounce

main
Eric Amodio 7 yıl önce
ebeveyn
işleme
4022f443a1
3 değiştirilmiş dosya ile 15 ekleme ve 14 silme
  1. +2
    -2
      src/currentLineController.ts
  2. +4
    -4
      src/git/gitContextTracker.ts
  3. +9
    -8
      src/system/function.ts

+ 2
- 2
src/currentLineController.ts Dosyayı Görüntüle

@ -1,5 +1,5 @@
'use strict';
import { Functions, IDeferred } from './system';
import { Functions, IDeferrable } from './system';
import { CancellationToken, ConfigurationChangeEvent, debug, DecorationRangeBehavior, DecorationRenderOptions, Disposable, ExtensionContext, Hover, HoverProvider, languages, Position, Range, StatusBarAlignment, StatusBarItem, TextDocument, TextEditor, TextEditorDecorationType, TextEditorSelectionChangeEvent, window } from 'vscode';
import { AnnotationController, FileAnnotationType } from './annotations/annotationController';
import { Annotations } from './annotations/annotations';
@ -36,7 +36,7 @@ export class CurrentLineController extends Disposable {
private _isAnnotating: boolean = false;
private _statusBarItem: StatusBarItem | undefined;
private _trackCurrentLineDisposable: Disposable | undefined;
private _updateBlameDebounced: ((line: number, editor: TextEditor) => Promise<void>) & IDeferred;
private _updateBlameDebounced: ((line: number, editor: TextEditor) => Promise<void>) & IDeferrable;
private _uri: GitUri;
constructor(

+ 4
- 4
src/git/gitContextTracker.ts Dosyayı Görüntüle

@ -1,5 +1,5 @@
'use strict';
import { Functions, IDeferred } from '../system';
import { Functions, IDeferrable } from '../system';
import { ConfigurationChangeEvent, Disposable, Event, EventEmitter, Range, TextDocumentChangeEvent, TextEditor, TextEditorSelectionChangeEvent, window, workspace } from 'vscode';
import { TextDocumentComparer } from '../comparers';
import { configuration } from '../configuration';
@ -70,10 +70,10 @@ export class GitContextTracker extends Disposable {
private readonly _context: Context = { state: { dirty: false } };
private readonly _disposable: Disposable;
private _listenersDisposable: Disposable | undefined;
private _fireDirtyStateChangedDebounced: (() => void) & IDeferred;
private _fireDirtyStateChangedDebounced: (() => void) & IDeferrable;
private _checkLineDirtyStateChangedDebounced: (() => void) & IDeferred;
private _fireLineDirtyStateChangedDebounced: (() => void) & IDeferred;
private _checkLineDirtyStateChangedDebounced: (() => void) & IDeferrable;
private _fireLineDirtyStateChangedDebounced: (() => void) & IDeferrable;
private _insiders = false;

+ 9
- 8
src/system/function.ts Dosyayı Görüntüle

@ -2,9 +2,10 @@
const _debounce = require('lodash.debounce');
const _once = require('lodash.once');
export interface IDeferred {
export interface IDeferrable {
cancel(): void;
flush(...args: any[]): void;
pending?: () => boolean;
}
interface IPropOfValue {
@ -13,22 +14,22 @@ interface IPropOfValue {
}
export namespace Functions {
export function debounce<T extends Function>(fn: T, wait?: number, options?: { leading?: boolean, maxWait?: number, track?: boolean, trailing?: boolean }): T & IDeferredan> & { pending?: () => boolean } {
export function debounce<T extends Function>(fn: T, wait?: number, options?: { leading?: boolean, maxWait?: number, track?: boolean, trailing?: boolean }): T & IDeferrable {
const { track, ...opts } = { track: false, ...(options || {}) } as { leading?: boolean, maxWait?: number, track?: boolean, trailing?: boolean };
if (track !== true) return _debounce(fn, wait, opts);
let pending = false;
const debounced = _debounce(function() {
const debounced = _debounce(function(this: any) {
pending = false;
return fn.apply(null, arguments);
} as any as T, wait, options) as T & IDeferred;
return fn.apply(this, arguments);
} as any as T, wait, options) as T & IDeferrable;
const tracked = function() {
const tracked = function(this: any) {
pending = true;
return debounced.apply(null, arguments);
} as any as T & IDeferredan> & { pending(): boolean};
return debounced.apply(this, arguments);
} as any as T & IDeferrable;
tracked.pending = function() { return pending; };
tracked.cancel = function() { return debounced.cancel.apply(debounced, arguments); };

Yükleniyor…
İptal
Kaydet