Pārlūkot izejas kodu

Clear signals after breakpoints model is disposed

Johan Mabille 5 gadi atpakaļ
vecāks
revīzija
c6c93594b2
2 mainītis faili ar 35 papildinājumiem un 21 dzēšanām
  1. 15 2
      src/breakpoints/index.ts
  2. 20 19
      src/handlers/cell.ts

+ 15 - 2
src/breakpoints/index.ts

@@ -2,7 +2,7 @@
 // Distributed under the terms of the Modified BSD License.
 
 import { Toolbar, ToolbarButton } from '@jupyterlab/apputils';
-
+import { IDisposable } from '@phosphor/disposable';
 import { Signal } from '@phosphor/signaling';
 import { Panel, PanelLayout, Widget } from '@phosphor/widgets';
 import { DebugProtocol } from 'vscode-debugprotocol';
@@ -77,7 +77,7 @@ export namespace Breakpoints {
     active: boolean;
   }
 
-  export class Model {
+  export class Model implements IDisposable {
     constructor(model: IBreakpoint[]) {
       this._breakpoints = model;
     }
@@ -134,6 +134,18 @@ export namespace Breakpoints {
       }
     }
 
+    get isDisposed(): boolean {
+      return this._isDisposed;
+    }
+
+    dispose(): void {
+      if (this._isDisposed) {
+        return;
+      }
+      this._isDisposed = true;
+      Signal.clearData(this);
+    }
+
     private _selectedType: SessionTypes;
     private _breakpointChanged = new Signal<this, IBreakpoint>(this);
     private _breakpoints: IBreakpoint[];
@@ -141,6 +153,7 @@ export namespace Breakpoints {
       console: [] as Breakpoints.IBreakpoint[],
       notebook: [] as Breakpoints.IBreakpoint[]
     };
+    private _isDisposed: boolean = false;
   }
 
   /**

+ 20 - 19
src/handlers/cell.ts

@@ -32,28 +32,29 @@ export class CellManager implements IDisposable {
 
   private onModelChanged() {
     this._debuggerModel = this._debuggerService.model;
-    if (this._debuggerModel) {
-      this.breakpointsModel = this._debuggerModel.breakpointsModel;
-
-      this._debuggerModel.variablesModel.changed.connect(() => {
-        this.cleanupHighlight();
-        const firstFrame = this._debuggerModel.callstackModel.frames[0];
-        if (!firstFrame) {
-          return;
-        }
-        this.showCurrentLine(firstFrame.line);
-      });
+    if (!this._debuggerModel) {
+      return;
+    }
+    this.breakpointsModel = this._debuggerModel.breakpointsModel;
 
-      this.breakpointsModel.changed.connect(async () => {
-        if (!this.activeCell || this.activeCell.isDisposed) {
-          return;
-        }
-        this.addBreakpointsToEditor(this.activeCell);
-      });
+    this._debuggerModel.variablesModel.changed.connect(() => {
+      this.cleanupHighlight();
+      const firstFrame = this._debuggerModel.callstackModel.frames[0];
+      if (!firstFrame) {
+        return;
+      }
+      this.showCurrentLine(firstFrame.line);
+    });
 
-      if (this.activeCell) {
-        this._debuggerModel.codeValue = this.activeCell.model.value;
+    this.breakpointsModel.changed.connect(async () => {
+      if (!this.activeCell || this.activeCell.isDisposed) {
+        return;
       }
+      this.addBreakpointsToEditor(this.activeCell);
+    });
+
+    if (this.activeCell) {
+      this._debuggerModel.codeValue = this.activeCell.model.value;
     }
   }