Skip to content

Commit

Permalink
Throttle status widget to prevent flashing updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kgryte committed May 19, 2020
1 parent cf3d9ac commit 6bdba11
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { IGitExtension } from './tokens';
import { addCloneButton } from './widgets/gitClone';
import { GitWidget } from './widgets/GitWidget';
import { gitIcon } from './style/icons';

import { sleep } from './utils';
export { Git, IGitExtension } from './tokens';

const RESOURCES = [
Expand Down Expand Up @@ -204,8 +204,43 @@ class StatusWidget extends Widget {
* Sets the current status.
*/
set status(text: string) {
this.node.textContent = 'Git: ' + text;
this._status = text;
if (!this._locked) {
this._lock();
this.refresh();
}
}

/**
* Refreshes the status widget.
*/
refresh(): void {
this.node.textContent = 'Git: ' + this._status;
}

/**
* Locks the status widget to prevent updates.
*
* ## Notes
*
* - This is used to throttle updates in order to prevent "flashing" messages.
*/
async _lock(): Promise<void> {
this._locked = true;
await sleep(500);
this._locked = false;
this.refresh();
}

/**
* Boolean indicating whether the status widget is accepting updates.
*/
private _locked = false;

/**
* Status string.
*/
private _status = '';
}

/**
Expand Down

0 comments on commit 6bdba11

Please sign in to comment.