소스 검색

Model contruction cleanup

Johan Mabille 5 년 전
부모
커밋
009006b95f
7개의 변경된 파일29개의 추가작업 그리고 36개의 파일을 삭제
  1. 4 4
      src/callstack/body.tsx
  2. 3 5
      src/callstack/index.ts
  3. 10 13
      src/debugger.ts
  4. 4 4
      src/index.ts
  5. 1 1
      src/service.ts
  6. 4 4
      src/variables/body/index.tsx
  7. 3 5
      src/variables/index.ts

+ 4 - 4
src/callstack/body.tsx

@@ -10,7 +10,7 @@ import { ReactWidget } from '@jupyterlab/apputils';
 import { ArrayExt } from '@phosphor/algorithm';
 
 export class Body extends ReactWidget {
-  constructor(model: Callstack.IModel) {
+  constructor(model: Callstack.Model) {
     super();
     this.model = model;
     this.addClass('jp-DebuggerCallstack-body');
@@ -20,10 +20,10 @@ export class Body extends ReactWidget {
     return <FramesComponent model={this.model} />;
   }
 
-  readonly model: Callstack.IModel;
+  readonly model: Callstack.Model;
 }
 
-const FramesComponent = ({ model }: { model: Callstack.IModel }) => {
+const FramesComponent = ({ model }: { model: Callstack.Model }) => {
   const [frames, setFrames] = useState(model.frames);
   const [selected, setSelected] = useState(model.frame);
 
@@ -33,7 +33,7 @@ const FramesComponent = ({ model }: { model: Callstack.IModel }) => {
   };
 
   useEffect(() => {
-    const updateFrames = (_: Callstack.IModel, updates: Callstack.IFrame[]) => {
+    const updateFrames = (_: Callstack.Model, updates: Callstack.IFrame[]) => {
       if (ArrayExt.shallowEqual(frames, updates)) {
         return;
       }

+ 3 - 5
src/callstack/index.ts

@@ -74,7 +74,7 @@ export class Callstack extends Panel {
     );
   }
 
-  readonly model: Callstack.IModel;
+  readonly model: Callstack.Model;
 }
 
 class CallstackHeader extends Widget {
@@ -96,9 +96,7 @@ class CallstackHeader extends Widget {
 export namespace Callstack {
   export interface IFrame extends DebugProtocol.StackFrame {}
 
-  export interface IModel {}
-
-  export class IModel implements IModel {
+  export class Model {
     constructor(model: IFrame[]) {
       this._state = model;
     }
@@ -136,6 +134,6 @@ export namespace Callstack {
   }
 
   export interface IOptions extends Panel.IOptions {
-    model: IModel;
+    model: Model;
   }
 }

+ 10 - 13
src/debugger.ts

@@ -1,8 +1,6 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import { IClientSession } from '@jupyterlab/apputils';
-
 import { CodeEditor } from '@jupyterlab/codeeditor';
 
 import { IDataConnector } from '@jupyterlab/coreutils';
@@ -37,7 +35,9 @@ export class Debugger extends SplitPanel {
     this.title.label = 'Debugger';
     this.title.iconClass = 'jp-BugIcon';
 
-    this.model = new Debugger.Model(options);
+    this.model = new Debugger.Model({
+      connector: options.connector
+    });
 
     this.sidebar = new Debugger.Sidebar(this.model);
     this.service = new DebugService(this.model);
@@ -76,8 +76,6 @@ export namespace Debugger {
   export interface IOptions {
     editorFactory: CodeEditor.Factory;
     connector?: IDataConnector<ReadonlyJSONValue>;
-    id?: string;
-    session?: IClientSession;
   }
 
   export class Sidebar extends SplitPanel {
@@ -103,19 +101,16 @@ export namespace Debugger {
   export class Model implements IDisposable {
     constructor(options: Debugger.Model.IOptions) {
       this.breakpointsModel = new Breakpoints.Model([]);
-      this.callstackModel = new Callstack.IModel([]);
-      this.variablesModel = new Variables.IModel([]);
+      this.callstackModel = new Callstack.Model([]);
+      this.variablesModel = new Variables.Model([]);
       this.connector = options.connector || null;
-      this.id = options.id;
       void this._populate();
     }
 
     readonly breakpointsModel: Breakpoints.Model;
-    readonly callstackModel: Callstack.IModel;
-    readonly variablesModel: Variables.IModel;
-
+    readonly callstackModel: Callstack.Model;
+    readonly variablesModel: Variables.Model;
     readonly connector: IDataConnector<ReadonlyJSONValue> | null;
-    readonly id: string;
 
     get mode(): IDebugger.Mode {
       return this._mode;
@@ -174,6 +169,8 @@ export namespace Debugger {
   }
 
   export namespace Model {
-    export interface IOptions extends Debugger.IOptions {}
+    export interface IOptions {
+      connector?: IDataConnector<ReadonlyJSONValue>;
+    }
   }
 }

+ 4 - 4
src/index.ts

@@ -386,10 +386,10 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
           widget = new MainAreaWidget({
             content: new Debugger({
               connector: state,
-              editorFactory,
-              id
+              editorFactory
             })
           });
+          widget.id = id;
 
           void tracker.add(widget);
 
@@ -430,9 +430,9 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
       void restorer.restore(tracker, {
         command: CommandIDs.create,
         args: widget => ({
-          id: widget.content.model.id
+          id: widget.id
         }),
-        name: widget => widget.content.model.id
+        name: widget => widget.id
       });
     }
 

+ 1 - 1
src/service.ts

@@ -159,7 +159,7 @@ export class DebugService implements IDebugger.IService {
     this._model.callstackModel.currentFrameChanged.connect(this.onChangeFrame);
   };
 
-  onChangeFrame = (_: Callstack.IModel, update: Callstack.IFrame) => {
+  onChangeFrame = (_: Callstack.Model, update: Callstack.IFrame) => {
     const frame = this.frames.find(ele => ele.id === update.id);
     if (frame && frame.scopes) {
       this._model.variablesModel.scopes = frame.scopes;

+ 4 - 4
src/variables/body/index.tsx

@@ -11,24 +11,24 @@ import React, { useState, useEffect } from 'react';
 import { ArrayExt } from '@phosphor/algorithm';
 
 export class Body extends ReactWidget {
-  constructor(model: Variables.IModel) {
+  constructor(model: Variables.Model) {
     super();
     this.model = model;
     this.addClass('jp-DebuggerVariables-body');
   }
 
-  model: Variables.IModel;
+  model: Variables.Model;
 
   render() {
     return <VariableComponent model={this.model} />;
   }
 }
 
-const VariableComponent = ({ model }: { model: Variables.IModel }) => {
+const VariableComponent = ({ model }: { model: Variables.Model }) => {
   const [data, setData] = useState(model.scopes);
 
   useEffect(() => {
-    const updateScopes = (_: Variables.IModel, update: Variables.IScope[]) => {
+    const updateScopes = (_: Variables.Model, update: Variables.IScope[]) => {
       if (ArrayExt.shallowEqual(data, update)) {
         return;
       }

+ 3 - 5
src/variables/index.ts

@@ -24,7 +24,7 @@ export class Variables extends Panel {
     this.addWidget(this.body);
   }
 
-  readonly model: Variables.IModel;
+  readonly model: Variables.Model;
   readonly header: VariablesHeader;
   readonly body: Widget;
 
@@ -59,9 +59,7 @@ export namespace Variables {
     variables: IVariable[];
   }
 
-  export interface IModel {}
-
-  export class IModel implements IModel {
+  export class Model {
     constructor(model: IScope[] = []) {
       this._state = model;
     }
@@ -118,6 +116,6 @@ export namespace Variables {
   }
 
   export interface IOptions extends Panel.IOptions {
-    model: IModel;
+    model: Model;
   }
 }