Skip to content

Commit

Permalink
Get rid of scheduleUpdate, retain minimum refresh time.
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-r-rose committed May 4, 2019
1 parent 8a93826 commit 1604811
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions packages/filebrowser/src/model.ts
Expand Up @@ -103,16 +103,13 @@ export class FileBrowserModel implements IDisposable {
}
};
window.addEventListener('beforeunload', this._unloadEventListener);
this._scheduleUpdate();
this._poll = new Poll({
factory: async () => {
if (this._requested) {
return this.refresh();
}
let date = new Date().getTime();
if (date - this._lastRefresh > refreshInterval) {
return this.refresh();
const date = new Date().getTime();
if (date - this._lastRefresh > MIN_REFRESH) {
return;
}
return this.refresh();
},
frequency: {
interval: refreshInterval,
Expand Down Expand Up @@ -243,7 +240,6 @@ export class FileBrowserModel implements IDisposable {
*/
refresh(): Promise<void> {
this._lastRefresh = new Date().getTime();
this._requested = false;
return this.cd('.');
}

Expand Down Expand Up @@ -600,7 +596,7 @@ export class FileBrowserModel implements IDisposable {

// If either the old value or the new value is in the current path, update.
if (value) {
this._scheduleUpdate();
this._poll.refresh();
this._populateSessions(sessions.running());
this._fileChanged.emit(change);
return;
Expand All @@ -619,18 +615,6 @@ export class FileBrowserModel implements IDisposable {
});
}

/**
* Handle internal model refresh logic.
*/
private _scheduleUpdate(): void {
let date = new Date().getTime();
if (date - this._lastRefresh > MIN_REFRESH) {
void this.refresh();
} else {
this._requested = true;
}
}

private _connectionFailure = new Signal<this, Error>(this);
private _fileChanged = new Signal<this, Contents.IChangedArgs>(this);
private _items: Contents.IModel[] = [];
Expand All @@ -642,7 +626,6 @@ export class FileBrowserModel implements IDisposable {
private _pendingPath: string | null = null;
private _refreshed = new Signal<this, void>(this);
private _lastRefresh = -1;
private _requested = false;
private _sessions: Session.IModel[] = [];
private _state: IStateDB | null = null;
private _driveName: string;
Expand Down

0 comments on commit 1604811

Please sign in to comment.