浏览代码

Clean up widget disposal

Steven Silvester 9 年之前
父节点
当前提交
7b20c25152
共有 2 个文件被更改,包括 5 次插入5 次删除
  1. 4 4
      examples/filebrowser/src/index.ts
  2. 1 1
      src/docmanager/index.ts

+ 4 - 4
examples/filebrowser/src/index.ts

@@ -26,10 +26,6 @@ import {
   showDialog, okButton
 } from 'jupyter-js-ui/lib/dialog';
 
-import {
-  CodeMirrorWidget
-} from 'jupyter-js-ui/lib/codemirror/widget';
-
 import {
   DockPanel
 } from 'phosphor-dockpanel';
@@ -71,6 +67,10 @@ function createApp(sessionsManager: NotebookSessionManager, specs: IKernelSpecId
       }
       dock.selectWidget(widget);
       activeWidget = widget;
+      widget.disposed.connect((w: DocumentWidget) => {
+        let index = widgets.indexOf(w);
+        widgets.splice(index, 1);
+      });
     }
   };
 

+ 1 - 1
src/docmanager/index.ts

@@ -801,7 +801,7 @@ class DocumentWidget extends Widget {
     // Remove the widget from the widget registry.
     let id = this._id;
     let index = this._widgets[id].indexOf(this);
-    this._widgets[id] = this._widgets[id].splice(index, 1);
+    this._widgets[id].splice(index, 1);
     // Dispose of the context if this is the last widget using it.
     if (!this._widgets[id].length) {
       this._manager.removeContext(id);