Browse Source

Clean up disposed handling of source.

Afshin Darian 6 years ago
parent
commit
b4f89a4e08

+ 2 - 2
packages/inspector/src/handler.ts

@@ -5,14 +5,14 @@ import { CodeEditor } from '@jupyterlab/codeeditor';
 
 import { IDataConnector, Text } from '@jupyterlab/coreutils';
 
+import { MimeModel, RenderMimeRegistry } from '@jupyterlab/rendermime';
+
 import { ReadonlyJSONObject } from '@phosphor/coreutils';
 
 import { IDisposable } from '@phosphor/disposable';
 
 import { ISignal, Signal } from '@phosphor/signaling';
 
-import { MimeModel, RenderMimeRegistry } from '@jupyterlab/rendermime';
-
 import { IInspector } from './inspector';
 
 /**

+ 14 - 4
packages/inspector/src/inspector.ts

@@ -45,20 +45,25 @@ export namespace IInspector {
    */
   export interface IInspectable {
     /**
-     * A signal emitted when the handler is disposed.
+     * A signal emitted when the inspector should clear all items.
      */
-    disposed: ISignal<any, void>;
+    cleared: ISignal<any, void>;
 
     /**
-     * A signal emitted when the inspector should clear all items.
+     * A signal emitted when the inspectable is disposed.
      */
-    cleared: ISignal<any, void>;
+    disposed: ISignal<any, void>;
 
     /**
      * A signal emitted when an inspector value is generated.
      */
     inspected: ISignal<any, IInspectorUpdate>;
 
+    /**
+     * Test whether the inspectable has been disposed.
+     */
+    isDisposed: boolean;
+
     /**
      * Indicates whether the inspectable source emits signals.
      *
@@ -115,6 +120,11 @@ export class InspectorPanel extends Panel implements IInspector {
       this._source.disposed.disconnect(this.onSourceDisposed, this);
     }
 
+    // Reject a source that is already disposed.
+    if (source && source.isDisposed) {
+      source = null;
+    }
+
     // Update source.
     this._source = source;
 

+ 2 - 0
tests/test-inspector/src/inspector.spec.ts

@@ -28,6 +28,8 @@ class TestInspectable implements IInspector.IInspectable {
 
   inspected = new Signal<this, IInspector.IInspectorUpdate>(this);
 
+  isDisposed = false;
+
   standby = false;
 }