فهرست منبع

Isolate the logic of the inspector plugins: console and notebook should consume the core inspector service and not have privileged access to private information.

Afshin Darian 8 سال پیش
والد
کامیت
24cf3d79e6
1فایلهای تغییر یافته به همراه21 افزوده شده و 21 حذف شده
  1. 21 21
      src/inspector/plugin.ts

+ 21 - 21
src/inspector/plugin.ts

@@ -42,11 +42,6 @@ import {
 } from './';
 
 
-/**
- * The inspector manager instance.
- */
-const manager = new InspectorManager();
-
 /**
  * The inspector instance tracker.
  */
@@ -61,6 +56,7 @@ const service: JupyterLabPlugin<IInspector> = {
   provides: IInspector,
   autoStart: true,
   activate: (app: JupyterLab, palette: ICommandPalette, restorer: IInstanceRestorer): IInspector => {
+    const manager = new InspectorManager();
     const category = 'Inspector';
     const command = CommandIDs.open;
     const label = 'Open Inspector';
@@ -113,9 +109,14 @@ const service: JupyterLabPlugin<IInspector> = {
  */
 const consolePlugin: JupyterLabPlugin<void> = {
   id: 'jupyter.extensions.console-inspector',
-  requires: [IConsoleTracker],
+  requires: [IInspector, IConsoleTracker],
   autoStart: true,
-  activate: (app: JupyterLab, consoles: IConsoleTracker): void => {
+  activate: (app: JupyterLab, manager: IInspector, consoles: IConsoleTracker): void => {
+    // Maintain association of new consoles with their respective handlers.
+    const handlers = new AttachedProperty<Widget, InspectionHandler>({
+      name: 'handler'
+    });
+
     // Create a handler for each console that is created.
     consoles.widgetAdded.connect((sender, parent) => {
       const session = parent.console.session;
@@ -124,7 +125,7 @@ const consolePlugin: JupyterLabPlugin<void> = {
       const handler = new InspectionHandler({ kernel, rendermime });
 
       // Associate the handler to the widget.
-      Private.handlers.set(parent, handler);
+      handlers.set(parent, handler);
 
       // Set the initial editor.
       let cell = parent.console.prompt;
@@ -143,13 +144,14 @@ const consolePlugin: JupyterLabPlugin<void> = {
       // Listen for parent disposal.
       parent.disposed.connect(() => { handler.dispose(); });
     });
+
     // Keep track of console instances and set inspector source.
     app.shell.currentChanged.connect((sender, args) => {
       let widget = args.newValue;
       if (!widget || !consoles.has(widget)) {
         return;
       }
-      let source = Private.handlers.get(widget);
+      let source = handlers.get(widget);
       if (source) {
         manager.source = source;
       }
@@ -162,9 +164,14 @@ const consolePlugin: JupyterLabPlugin<void> = {
  */
 const notebookPlugin: JupyterLabPlugin<void> = {
   id: 'jupyter.extensions.notebook-inspector',
-  requires: [INotebookTracker],
+  requires: [IInspector, INotebookTracker],
   autoStart: true,
-  activate: (app: JupyterLab, notebooks: INotebookTracker): void => {
+  activate: (app: JupyterLab, manager: IInspector, notebooks: INotebookTracker): void => {
+    // Maintain association of new notebooks with their respective handlers.
+    const handlers = new AttachedProperty<Widget, InspectionHandler>({
+      name: 'handler'
+    });
+
     // Create a handler for each notebook that is created.
     notebooks.widgetAdded.connect((sender, parent) => {
       const kernel = parent.kernel;
@@ -172,7 +179,7 @@ const notebookPlugin: JupyterLabPlugin<void> = {
       const handler = new InspectionHandler({ kernel, rendermime });
 
       // Associate the handler to the widget.
-      Private.handlers.set(parent, handler);
+      handlers.set(parent, handler);
 
       // Set the initial editor.
       let cell = parent.notebook.activeCell;
@@ -191,13 +198,14 @@ const notebookPlugin: JupyterLabPlugin<void> = {
       // Listen for parent disposal.
       parent.disposed.connect(() => { handler.dispose(); });
     });
+
     // Keep track of notebook instances and set inspector source.
     app.shell.currentChanged.connect((sender, args) => {
       let widget = args.newValue;
       if (!widget || !notebooks.has(widget)) {
         return;
       }
-      let source = Private.handlers.get(widget);
+      let source = handlers.get(widget);
       if (source) {
         manager.source = source;
       }
@@ -230,12 +238,4 @@ namespace Private {
       type: 'hints'
     }
   ];
-
-  /**
-   * A property that associates inspection handlers with their referent widgets.
-   */
-  export
-  const handlers = new AttachedProperty<Widget, InspectionHandler>({
-    name: 'handler'
-  });
 }