浏览代码

refactor after code review

Borys Palka 5 年之前
父节点
当前提交
c6300ada70
共有 3 个文件被更改,包括 15 次插入47 次删除
  1. 13 4
      src/service.ts
  2. 1 1
      src/variables/body/index.tsx
  3. 1 42
      src/variables/index.ts

+ 13 - 4
src/service.ts

@@ -333,12 +333,21 @@ export class DebugService implements IDebugger {
     const reply = await this.session.sendRequest('variables', {
       variablesReference: variable.variablesReference
     });
-    let newVariable = { ...variable };
-    reply.body.variables.forEach((ele: DebugProtocol.Variable) => {
-      newVariable = { [ele.evaluateName]: ele, ...newVariable };
+    let newVariable = { ...variable, haveMoreDetails: Symbol('haveDetails') };
+
+    reply.body.variables.forEach((variable: DebugProtocol.Variable) => {
+      newVariable = { [variable.name]: variable, ...newVariable };
+    });
+
+    const newScope = this._model.variablesModel.scopes.map(scope => {
+      const findIndex = scope.variables.findIndex(
+        ele => ele.variablesReference === variable.variablesReference
+      );
+      scope.variables[findIndex] = newVariable;
+      return { ...scope };
     });
 
-    this._model.variablesModel.currentVariable = newVariable;
+    this._model.variablesModel.scopes = [...newScope];
 
     return reply.body.variables;
   };

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

@@ -69,7 +69,7 @@ const VariableComponent = ({ model }: { model: Variables.Model }) => {
     const converted = scopes.map(scope => {
       const newVariable = scope.variables.map(variable => {
         const func = () => {
-          model.getMoreDataOfVariable(variable);
+          model.expandVariable(variable);
         };
 
         if (variable.haveMoreDetails || variable.variablesReference === 0) {

+ 1 - 42
src/variables/index.ts

@@ -71,29 +71,6 @@ export namespace Variables {
       return this._changed;
     }
 
-    get currentVariable(): IVariable {
-      return this._currentVariable;
-    }
-
-    set currentVariable(variable: IVariable) {
-      if (this._currentVariable === variable) {
-        return;
-      }
-
-      variable.haveMoreDetails = Symbol('haveDetails');
-      this._currentVariable = variable;
-      this._currentChanged.emit(variable);
-
-      const newScope = this.scopes.map(scope => {
-        const findIndex = scope.variables.findIndex(
-          ele => ele.variablesReference === variable.variablesReference
-        );
-        scope.variables[findIndex] = variable;
-        return { ...scope };
-      });
-      this.scopes = [...newScope];
-    }
-
     get scopes(): IScope[] {
       return this._state;
     }
@@ -103,33 +80,15 @@ export namespace Variables {
       this._changed.emit();
     }
 
-    get variables(): IVariable[] {
-      return this._currentScope ? this._currentScope.variables : [];
-    }
-
-    set variables(variables: IVariable[]) {
-      this._currentScope.variables = variables;
-      this._changed.emit();
-    }
-
     get variableExpanded(): ISignal<this, IVariable> {
       return this._variableExpanded;
     }
 
-    getCurrentVariables(): IVariable[] {
-      return this.variables;
-    }
-
-    getMoreDataOfVariable(variable: IVariable) {
+    expandVariable(variable: IVariable) {
       this._variableExpanded.emit(variable);
     }
 
     protected _state: IScope[];
-
-    private _currentVariable: IVariable;
-    private _currentScope: IScope;
-
-    private _currentChanged = new Signal<this, IVariable>(this);
     private _variableExpanded = new Signal<this, IVariable>(this);
     private _changed = new Signal<this, void>(this);
   }