From 3601a650f41a7b471f4549308c488eb2bef43ba7 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 7 Sep 2018 14:06:17 -0400 Subject: [PATCH] move some logic to another class --- src/app/debugger/debuggerUI.js | 2 +- src/app/debugger/debuggerUI/StepManager.js | 163 +++++++++++++++------ 2 files changed, 119 insertions(+), 46 deletions(-) diff --git a/src/app/debugger/debuggerUI.js b/src/app/debugger/debuggerUI.js index b5713aa225..e974fda9f5 100644 --- a/src/app/debugger/debuggerUI.js +++ b/src/app/debugger/debuggerUI.js @@ -33,7 +33,7 @@ class DebuggerUI { }) this.transactionDebugger.event.register('breakpointStep', function (step) { - self.stepManager.jumpTo(step) + self.stepManager.step_manager.jumpTo(step) }) this.debugger_ui.event.register('indexChanged', function (index) { diff --git a/src/app/debugger/debuggerUI/StepManager.js b/src/app/debugger/debuggerUI/StepManager.js index 275d162434..f4cdc41f07 100644 --- a/src/app/debugger/debuggerUI/StepManager.js +++ b/src/app/debugger/debuggerUI/StepManager.js @@ -7,6 +7,66 @@ var yo = require('yo-yo') var ButtonNavigator = require('./ButtonNavigator') var Slider = require('./Slider') +class DebuggerStepManager { + + constructor (_parent, _traceManager) { + this.event = new EventManager() + this._parent = _parent + this.parent = _parent.debugger + this.traceManager = _traceManager + this.revertionPoint = null + this.currentStepIndex = 0 + } + + stepIntoBack () { + if (!this.traceManager.isLoaded()) return + var step = this.currentStepIndex - 1 + this.currentStepIndex = step + if (!this.traceManager.inRange(step)) { + return + } + this.event.trigger('stepChanged', [step]) + } + + stepIntoForward () { + if (!this.traceManager.isLoaded()) return + var step = this.currentStepIndex + 1 + this.currentStepIndex = step + if (!this.traceManager.inRange(step)) { + return + } + this.event.trigger('stepChanged', [step]) + } + + stepOverBack () { + if (!this.traceManager.isLoaded()) return + var step = this.traceManager.findStepOverBack(this.currentStepIndex) + this.currentStepIndex = step + this.event.trigger('stepChanged', [step]) + } + + stepOverForward () { + if (!this.traceManager.isLoaded()) return + var step = this.traceManager.findStepOverForward(this.currentStepIndex) + this.currentStepIndex = step + this.event.trigger('stepChanged', [step]) + } + + jumpOut () { + if (!this.traceManager.isLoaded()) return + var step = this.traceManager.findStepOut(this.currentStepIndex) + this.currentStepIndex = step + this.event.trigger('stepChanged', [step]) + } + + jumpTo (step) { + if (!this.traceManager.inRange(step)) return + this.currentStepIndex = step + this.event.trigger('stepChanged', [step]) + } + +} + function StepManager (_parent, _traceManager) { this.event = new EventManager() this._parent = _parent @@ -14,6 +74,8 @@ function StepManager (_parent, _traceManager) { this.traceManager = _traceManager this.revertionPoint = null + this.step_manager = new DebuggerStepManager(_parent, _traceManager) + this.startSlider() this.startButtonNavigator() } @@ -39,7 +101,7 @@ StepManager.prototype.startSlider = function () { this.parent.callTree.event.register('callTreeReady', () => { if (!this.slider) return if (this.parent.callTree.functionCallStack.length) { - this.jumpTo(this.parent.callTree.functionCallStack[0]) + this.step_manager.jumpTo(this.parent.callTree.functionCallStack[0]) } }) } @@ -85,22 +147,22 @@ StepManager.prototype.startButtonNavigator = function () { }) this.buttonNavigator.event.register('stepIntoBack', this, function () { - self.stepIntoBack() + self.step_manager.stepIntoBack() }) this.buttonNavigator.event.register('stepIntoForward', this, function () { - self.stepIntoForward() + self.step_manager.stepIntoForward() }) this.buttonNavigator.event.register('stepOverBack', this, function () { - self.stepOverBack() + self.step_manager.stepOverBack() }) this.buttonNavigator.event.register('stepOverForward', this, function () { - self.stepOverForward() + self.step_manager.stepOverForward() }) this.buttonNavigator.event.register('jumpOut', this, function () { - self.jumpOut() + self.step_manager.jumpOut() }) this.buttonNavigator.event.register('jumpToException', this, function () { - self.jumpTo(self.revertionPoint) + self.step_manager.jumpTo(self.revertionPoint) }) this.buttonNavigator.event.register('jumpNextBreakpoint', (exceptionIndex) => { self.parent.breakpointManager.jumpNextBreakpoint(self._parent.currentStepIndex, true) @@ -108,6 +170,12 @@ StepManager.prototype.startButtonNavigator = function () { this.buttonNavigator.event.register('jumpPreviousBreakpoint', (exceptionIndex) => { self.parent.breakpointManager.jumpPreviousBreakpoint(self._parent.currentStepIndex, true) }) + + this.step_manager.event.register('stepChanged', (step) => { + console.dir("==> stepChanged") + console.dir(step) + self.updateStep(step) + }) } StepManager.prototype.init = function () { @@ -115,57 +183,62 @@ StepManager.prototype.init = function () { this.changeState(0) } -StepManager.prototype.jumpTo = function (step) { - if (!this.traceManager.inRange(step)) return - this.slider.setValue(step) - this.changeState(step) -} +// StepManager.prototype.jumpTo = function (step) { +// if (!this.traceManager.inRange(step)) return +// this.slider.setValue(step) +// this.changeState(step) +// } StepManager.prototype.sliderMoved = function (step) { if (!this.traceManager.inRange(step)) return this.changeState(step) } -StepManager.prototype.stepIntoForward = function () { - if (!this.traceManager.isLoaded()) return - var step = this.currentStepIndex + 1 - if (!this.traceManager.inRange(step)) { - return - } - this.slider.setValue(step) - this.changeState(step) -} +// StepManager.prototype.stepIntoForward = function () { +// if (!this.traceManager.isLoaded()) return +// var step = this.currentStepIndex + 1 +// if (!this.traceManager.inRange(step)) { +// return +// } +// this.slider.setValue(step) +// this.changeState(step) +// } -StepManager.prototype.stepIntoBack = function () { - if (!this.traceManager.isLoaded()) return - var step = this.currentStepIndex - 1 - if (!this.traceManager.inRange(step)) { - return - } +StepManager.prototype.updateStep = function (step) { this.slider.setValue(step) this.changeState(step) } -StepManager.prototype.stepOverForward = function () { - if (!this.traceManager.isLoaded()) return - var step = this.traceManager.findStepOverForward(this.currentStepIndex) - this.slider.setValue(step) - this.changeState(step) -} +// StepManager.prototype.stepIntoBack = function () { +// if (!this.traceManager.isLoaded()) return +// var step = this.currentStepIndex - 1 +// if (!this.traceManager.inRange(step)) { +// return +// } +// this.slider.setValue(step) +// this.changeState(step) +// } -StepManager.prototype.stepOverBack = function () { - if (!this.traceManager.isLoaded()) return - var step = this.traceManager.findStepOverBack(this.currentStepIndex) - this.slider.setValue(step) - this.changeState(step) -} +// StepManager.prototype.stepOverForward = function () { +// if (!this.traceManager.isLoaded()) return +// var step = this.traceManager.findStepOverForward(this.currentStepIndex) +// this.slider.setValue(step) +// this.changeState(step) +// } -StepManager.prototype.jumpOut = function () { - if (!this.traceManager.isLoaded()) return - var step = this.traceManager.findStepOut(this.currentStepIndex) - this.slider.setValue(step) - this.changeState(step) -} +// StepManager.prototype.stepOverBack = function () { +// if (!this.traceManager.isLoaded()) return +// var step = this.traceManager.findStepOverBack(this.currentStepIndex) +// this.slider.setValue(step) +// this.changeState(step) +// } + +// StepManager.prototype.jumpOut = function () { +// if (!this.traceManager.isLoaded()) return +// var step = this.traceManager.findStepOut(this.currentStepIndex) +// this.slider.setValue(step) +// this.changeState(step) +// } StepManager.prototype.changeState = function (step) { const self = this