Browse Source

Use changed signal for models

Jeremy Tuloup 5 years ago
parent
commit
73480c6efe

+ 3 - 3
src/breakpoints/body.tsx

@@ -35,10 +35,10 @@ const BreakpointsComponent = ({ model }: { model: Breakpoints.Model }) => {
       setBreakpoints(updates);
       setBreakpoints(updates);
     };
     };
 
 
-    model.breakpointsChanged.connect(updateBreakpoints);
+    model.changed.connect(updateBreakpoints);
 
 
     return () => {
     return () => {
-      model.breakpointsChanged.disconnect(updateBreakpoints);
+      model.changed.disconnect(updateBreakpoints);
     };
     };
   });
   });
 
 
@@ -98,7 +98,7 @@ const BreakpointComponent = ({
         checked={active}
         checked={active}
       />
       />
       <span>
       <span>
-        {breakpoint.source.path} : {breakpoint.line}
+        {breakpoint.source.name} : {breakpoint.line}
       </span>
       </span>
     </div>
     </div>
   );
   );

+ 2 - 2
src/breakpoints/index.ts

@@ -82,7 +82,7 @@ export namespace Breakpoints {
       this._breakpoints = model;
       this._breakpoints = model;
     }
     }
 
 
-    breakpointsChanged = new Signal<this, IBreakpoint[]>(this);
+    changed = new Signal<this, IBreakpoint[]>(this);
 
 
     get breakpoints(): IBreakpoint[] {
     get breakpoints(): IBreakpoint[] {
       return this._breakpoints;
       return this._breakpoints;
@@ -94,7 +94,7 @@ export namespace Breakpoints {
 
 
     set breakpoints(breakpoints: IBreakpoint[]) {
     set breakpoints(breakpoints: IBreakpoint[]) {
       this._breakpoints = [...breakpoints];
       this._breakpoints = [...breakpoints];
-      this.breakpointsChanged.emit(this._breakpoints);
+      this.changed.emit(this._breakpoints);
     }
     }
 
 
     set breakpoint(breakpoint: IBreakpoint) {
     set breakpoint(breakpoint: IBreakpoint) {

+ 0 - 10
src/debugger.ts

@@ -151,14 +151,6 @@ export namespace Debugger {
       this._codeValue = observableString;
       this._codeValue = observableString;
     }
     }
 
 
-    get currentLineChanged() {
-      return this._currentLineChanged;
-    }
-
-    get linesCleared() {
-      return this._linesCleared;
-    }
-
     dispose(): void {
     dispose(): void {
       this._isDisposed = true;
       this._isDisposed = true;
     }
     }
@@ -175,8 +167,6 @@ export namespace Debugger {
     private _isDisposed = false;
     private _isDisposed = false;
     private _mode: IDebugger.Mode;
     private _mode: IDebugger.Mode;
     private _modeChanged = new Signal<this, IDebugger.Mode>(this);
     private _modeChanged = new Signal<this, IDebugger.Mode>(this);
-    private _currentLineChanged = new Signal<this, number>(this);
-    private _linesCleared = new Signal<this, void>(this);
   }
   }
 
 
   export namespace Sidebar {
   export namespace Sidebar {

+ 7 - 6
src/handlers/cell.ts

@@ -25,15 +25,16 @@ export class CellManager implements IDisposable {
     this.activeCell = options.activeCell;
     this.activeCell = options.activeCell;
     this.onActiveCellChanged();
     this.onActiveCellChanged();
 
 
-    this._debuggerModel.currentLineChanged.connect((_, lineNumber) => {
-      this.showCurrentLine(lineNumber);
-    });
-
-    this._debuggerModel.linesCleared.connect(() => {
+    this._debuggerModel.variablesModel.changed.connect(() => {
       this.cleanupHighlight();
       this.cleanupHighlight();
+      const firstFrame = this._debuggerModel.callstackModel.frames[0];
+      if (!firstFrame) {
+        return;
+      }
+      this.showCurrentLine(firstFrame.line);
     });
     });
 
 
-    this.breakpointsModel.breakpointsChanged.connect(async () => {
+    this.breakpointsModel.changed.connect(async () => {
       if (!this.activeCell || this.activeCell.isDisposed) {
       if (!this.activeCell || this.activeCell.isDisposed) {
         return;
         return;
       }
       }

+ 3 - 2
src/service.ts

@@ -158,7 +158,6 @@ export class DebugService implements IDebugger {
       });
       });
       if (index === 0) {
       if (index === 0) {
         this._model.variablesModel.scopes = values;
         this._model.variablesModel.scopes = values;
-        this._model.currentLineChanged.emit(frame.line);
       }
       }
     });
     });
 
 
@@ -275,7 +274,6 @@ export class DebugService implements IDebugger {
   };
   };
 
 
   private onContinued() {
   private onContinued() {
-    this._model.linesCleared.emit();
     this._model.callstackModel.frames = [];
     this._model.callstackModel.frames = [];
     this._model.variablesModel.scopes = [];
     this._model.variablesModel.scopes = [];
   }
   }
@@ -290,7 +288,10 @@ export class DebugService implements IDebugger {
   private _sessionChanged = new Signal<IDebugger, IDebugger.ISession>(this);
   private _sessionChanged = new Signal<IDebugger, IDebugger.ISession>(this);
   private _eventMessage = new Signal<IDebugger, IDebugger.ISession.Event>(this);
   private _eventMessage = new Signal<IDebugger, IDebugger.ISession.Event>(this);
   private _model: Debugger.Model;
   private _model: Debugger.Model;
+
+  // TODO: remove frames from the service
   private frames: Frame[] = [];
   private frames: Frame[] = [];
+
   // TODO: move this in model
   // TODO: move this in model
   private _threadStopped = new Set();
   private _threadStopped = new Set();
 }
 }

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

@@ -28,17 +28,17 @@ const VariableComponent = ({ model }: { model: Variables.Model }) => {
   const [data, setData] = useState(model.scopes);
   const [data, setData] = useState(model.scopes);
 
 
   useEffect(() => {
   useEffect(() => {
-    const updateScopes = (_: Variables.Model, update: Variables.IScope[]) => {
-      if (ArrayExt.shallowEqual(data, update)) {
+    const updateScopes = () => {
+      if (ArrayExt.shallowEqual(data, model.scopes)) {
         return;
         return;
       }
       }
-      setData(update);
+      setData(model.scopes);
     };
     };
 
 
-    model.scopesChanged.connect(updateScopes);
+    model.changed.connect(updateScopes);
 
 
     return () => {
     return () => {
-      model.scopesChanged.disconnect(updateScopes);
+      model.changed.disconnect(updateScopes);
     };
     };
   });
   });
 
 

+ 7 - 11
src/variables/index.ts

@@ -64,8 +64,8 @@ export namespace Variables {
       this._state = model;
       this._state = model;
     }
     }
 
 
-    get scopesChanged(): ISignal<this, IScope[]> {
-      return this._scopesChanged;
+    get changed(): ISignal<this, void> {
+      return this._changed;
     }
     }
 
 
     get currentVariable(): IVariable {
     get currentVariable(): IVariable {
@@ -77,7 +77,7 @@ export namespace Variables {
         return;
         return;
       }
       }
       this._currentVariable = variable;
       this._currentVariable = variable;
-      this._currentChanged.emit(variable);
+      this._currentVariableChanged.emit(variable);
     }
     }
 
 
     get scopes(): IScope[] {
     get scopes(): IScope[] {
@@ -86,7 +86,7 @@ export namespace Variables {
 
 
     set scopes(scopes: IScope[]) {
     set scopes(scopes: IScope[]) {
       this._state = scopes;
       this._state = scopes;
-      this._scopesChanged.emit(scopes);
+      this._changed.emit();
     }
     }
 
 
     get variables(): IVariable[] {
     get variables(): IVariable[] {
@@ -95,10 +95,7 @@ export namespace Variables {
 
 
     set variables(variables: IVariable[]) {
     set variables(variables: IVariable[]) {
       this._currentScope.variables = variables;
       this._currentScope.variables = variables;
-    }
-
-    get variablesChanged(): ISignal<this, IVariable[]> {
-      return this._variablesChanged;
+      this._changed.emit();
     }
     }
 
 
     getCurrentVariables(): IVariable[] {
     getCurrentVariables(): IVariable[] {
@@ -110,9 +107,8 @@ export namespace Variables {
     private _currentVariable: IVariable;
     private _currentVariable: IVariable;
     private _currentScope: IScope;
     private _currentScope: IScope;
 
 
-    private _currentChanged = new Signal<this, IVariable>(this);
-    private _variablesChanged = new Signal<this, IVariable[]>(this);
-    private _scopesChanged = new Signal<this, IScope[]>(this);
+    private _changed = new Signal<this, void>(this);
+    private _currentVariableChanged = new Signal<this, IVariable>(this);
   }
   }
 
 
   export interface IOptions extends Panel.IOptions {
   export interface IOptions extends Panel.IOptions {