浏览代码

Use Debouncer in LabShell.

Afshin T. Darian 6 年之前
父节点
当前提交
f2a3f45e00
共有 1 个文件被更改,包括 17 次插入11 次删除
  1. 17 11
      packages/application/src/shell.ts

+ 17 - 11
packages/application/src/shell.ts

@@ -1,6 +1,8 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import { Debouncer } from '@jupyterlab/coreutils';
+
 import { DocumentRegistry } from '@jupyterlab/docregistry';
 
 import { ArrayExt, find, IIterator, iter, toArray } from '@phosphor/algorithm';
@@ -539,6 +541,17 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
     this._onLayoutModified();
   }
 
+  /**
+   * Dispose the shell.
+   */
+  dispose(): void {
+    if (this.isDisposed) {
+      return;
+    }
+    this._layoutDebouncer.dispose();
+    super.dispose();
+  }
+
   /**
    * Expand the left area.
    *
@@ -923,16 +936,7 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
    * Handle a change to the layout.
    */
   private _onLayoutModified(): void {
-    // The dock can emit layout modified signals while in transient
-    // states (for instance, when switching from single-document to
-    // multiple-document mode). In those states, it can be unreliable
-    // for the signal consumers to query layout properties.
-    // We fix this by debouncing the layout modified signal so that it
-    // is only emitted after rearranging is done.
-    window.clearTimeout(this._debouncer);
-    this._debouncer = window.setTimeout(() => {
-      this._layoutModified.emit(undefined);
-    }, 0);
+    void this._layoutDebouncer.invoke();
   }
 
   /**
@@ -963,6 +967,9 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
   private _dockPanel: DockPanel;
   private _isRestored = false;
   private _layoutModified = new Signal<this, void>(this);
+  private _layoutDebouncer = new Debouncer(() => {
+    this._layoutModified.emit(undefined);
+  }, 0);
   private _leftHandler: Private.SideBarHandler;
   private _restored = new PromiseDelegate<ILabShell.ILayout>();
   private _rightHandler: Private.SideBarHandler;
@@ -970,7 +977,6 @@ export class LabShell extends Widget implements JupyterFrontEnd.IShell {
   private _headerPanel: Panel;
   private _topPanel: Panel;
   private _bottomPanel: Panel;
-  private _debouncer = 0;
   private _mainOptionsCache = new Map<Widget, DocumentRegistry.IOpenOptions>();
   private _sideOptionsCache = new Map<Widget, DocumentRegistry.IOpenOptions>();
 }