Commit 66576387 authored by yann300's avatar yann300

- clean

- load EventManager as object
parent d63a3e10
...@@ -4,7 +4,9 @@ var style = require('./basicStyles') ...@@ -4,7 +4,9 @@ var style = require('./basicStyles')
module.exports = React.createClass({ module.exports = React.createClass({
contextTypes: { contextTypes: {
codeManager: React.PropTypes.object codeManager: React.PropTypes.object,
root: React.PropTypes.object,
tx: React.PropTypes.object
}, },
getInitialState: function () { getInitialState: function () {
...@@ -23,10 +25,14 @@ module.exports = React.createClass({ ...@@ -23,10 +25,14 @@ module.exports = React.createClass({
}, },
componentDidMount: function () { componentDidMount: function () {
var self = this
this.context.codeManager.register('indexChanged', this, this.indexChanged) this.context.codeManager.register('indexChanged', this, this.indexChanged)
this.context.codeManager.register('codeChanged', this, this.codeChanged) this.context.codeManager.register('codeChanged', this, this.codeChanged)
this.context.codeManager.register('loadingCode', this, function (address) { this.context.codeManager.register('loadingCode', this, function (address) {
}) })
this.context.root.register('indexChanged', this, function (index) {
self.context.codeManager.resolveStep(index, self.context.tx)
})
}, },
indexChanged: function (index) { indexChanged: function (index) {
......
...@@ -9,12 +9,6 @@ module.exports = React.createClass({ ...@@ -9,12 +9,6 @@ module.exports = React.createClass({
root: React.PropTypes.object root: React.PropTypes.object
}, },
getDefaultProps: function () {
return {
currentStepIndex: -1
}
},
getInitialState: function () { getInitialState: function () {
return { return {
data: null data: null
......
...@@ -9,12 +9,6 @@ module.exports = React.createClass({ ...@@ -9,12 +9,6 @@ module.exports = React.createClass({
root: React.PropTypes.object root: React.PropTypes.object
}, },
getDefaultProps: function () {
return {
currentStepIndex: -1
}
},
getInitialState: function () { getInitialState: function () {
return { return {
data: null data: null
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
var traceManagerUtil = require('./traceManagerUtil') var traceManagerUtil = require('./traceManagerUtil')
var codeResolver = require('./codeResolver') var codeResolver = require('./codeResolver')
var util = require('./util') var util = require('./util')
var eventManager = require('./eventManager') var EventManager = require('./eventManager')
/* /*
resolve contract code referenced by vmtrace in order to be used by asm listview. resolve contract code referenced by vmtrace in order to be used by asm listview.
...@@ -14,7 +14,7 @@ var eventManager = require('./eventManager') ...@@ -14,7 +14,7 @@ var eventManager = require('./eventManager')
*/ */
function CodeManager (_web3, _traceManager) { function CodeManager (_web3, _traceManager) {
util.extend(this, eventManager) util.extend(this, new EventManager())
this.web3 = _web3 this.web3 = _web3
this.isLoading = false this.isLoading = false
this.traceManager = _traceManager this.traceManager = _traceManager
......
...@@ -5,7 +5,7 @@ var StepManager = require('./stepManager') ...@@ -5,7 +5,7 @@ var StepManager = require('./stepManager')
var VmDebugger = require('./vmDebugger') var VmDebugger = require('./vmDebugger')
var style = require('./basicStyles') var style = require('./basicStyles')
var util = require('./util') var util = require('./util')
var eventManager = require('./eventManager') var EventManager = require('./eventManager')
module.exports = React.createClass({ module.exports = React.createClass({
getInitialState: function () { getInitialState: function () {
...@@ -14,7 +14,7 @@ module.exports = React.createClass({ ...@@ -14,7 +14,7 @@ module.exports = React.createClass({
tx: null tx: null
} }
}, },
childContextTypes: { childContextTypes: {
web3: React.PropTypes.object, web3: React.PropTypes.object,
traceManager: React.PropTypes.object, traceManager: React.PropTypes.object,
...@@ -49,11 +49,10 @@ module.exports = React.createClass({ ...@@ -49,11 +49,10 @@ module.exports = React.createClass({
this.setState({ this.setState({
currentStepIndex: stepIndex currentStepIndex: stepIndex
}) })
this.props.context.codeManager.resolveStep(stepIndex, this.state.tx)
}, },
componentWillMount: function () { componentWillMount: function () {
util.extend(this, eventManager) util.extend(this, new EventManager())
}, },
startDebugging: function (blockNumber, txIndex, tx) { startDebugging: function (blockNumber, txIndex, tx) {
...@@ -68,8 +67,7 @@ module.exports = React.createClass({ ...@@ -68,8 +67,7 @@ module.exports = React.createClass({
this.props.context.traceManager.resolveTrace(tx, function (success) { this.props.context.traceManager.resolveTrace(tx, function (success) {
console.log('trace loaded ' + success) console.log('trace loaded ' + success)
if (success) { if (success) {
self.stepChanged(0) self.trigger('newTraceLoaded')
self.refs.stepManager.newTraceAvailable()
} else { } else {
console.log('trace not loaded') console.log('trace not loaded')
} }
......
'use strict' 'use strict'
module.exports = { function EventManager () {
registered: {}, this.registered = {}
}
register: function (eventName, obj, func) { EventManager.prototype.unregister = function (eventName, obj) {
if (!this.registered[eventName]) { for (var reg in this.registered[eventName]) {
this.registered[eventName] = [] if (this.registered[eventName][reg] && this.registered[eventName][reg].obj === obj) {
this.registered[eventName].splice(reg, 1)
return
} }
this.registered[eventName].push({ }
obj: obj, }
func: func
})
},
trigger: function (eventName, args) { EventManager.prototype.register = function (eventName, obj, func) {
for (var listener in this.registered[eventName]) { if (!this.registered[eventName]) {
var l = this.registered[eventName][listener] this.registered[eventName] = []
l.func.apply(l.obj, args)
}
} }
this.registered[eventName].push({
obj: obj,
func: func
})
}
EventManager.prototype.trigger = function (eventName, args) {
for (var listener in this.registered[eventName]) {
var l = this.registered[eventName][listener]
l.func.apply(l.obj, args)
}
} }
module.exports = EventManager
...@@ -10,12 +10,6 @@ module.exports = React.createClass({ ...@@ -10,12 +10,6 @@ module.exports = React.createClass({
root: React.PropTypes.object root: React.PropTypes.object
}, },
getDefaultProps: function () {
return {
currentStepIndex: -1
}
},
getInitialState: function () { getInitialState: function () {
return { return {
data: null data: null
......
...@@ -9,12 +9,6 @@ module.exports = React.createClass({ ...@@ -9,12 +9,6 @@ module.exports = React.createClass({
root: React.PropTypes.object root: React.PropTypes.object
}, },
getDefaultProps: function () {
return {
currentStepIndex: -1
}
},
getInitialState: function () { getInitialState: function () {
return { return {
data: null data: null
......
...@@ -3,8 +3,6 @@ var React = require('react') ...@@ -3,8 +3,6 @@ var React = require('react')
var ButtonNavigator = require('./buttonNavigator') var ButtonNavigator = require('./buttonNavigator')
var Slider = require('./slider') var Slider = require('./slider')
var style = require('./basicStyles') var style = require('./basicStyles')
var util = require('./util')
var eventManager = require('./eventManager')
module.exports = React.createClass({ module.exports = React.createClass({
propTypes: { propTypes: {
...@@ -12,7 +10,8 @@ module.exports = React.createClass({ ...@@ -12,7 +10,8 @@ module.exports = React.createClass({
}, },
contextTypes: { contextTypes: {
traceManager: React.PropTypes.object traceManager: React.PropTypes.object,
root: React.PropTypes.object
}, },
getInitialState: function () { getInitialState: function () {
...@@ -43,7 +42,10 @@ module.exports = React.createClass({ ...@@ -43,7 +42,10 @@ module.exports = React.createClass({
}, },
componentDidMount: function () { componentDidMount: function () {
// util.extend(this, eventManager) var self = this
this.context.root.register('newTraceLoaded', this, function () {
self.newTraceAvailable()
})
this.changeState(-1) this.changeState(-1)
}, },
...@@ -53,7 +55,7 @@ module.exports = React.createClass({ ...@@ -53,7 +55,7 @@ module.exports = React.createClass({
init: function () { init: function () {
this.refs.slider.setValue(0) this.refs.slider.setValue(0)
this.changeState(-1) this.changeState(0)
}, },
newTraceAvailable: function () { newTraceAvailable: function () {
...@@ -64,7 +66,6 @@ module.exports = React.createClass({ ...@@ -64,7 +66,6 @@ module.exports = React.createClass({
console.log(error) console.log(error)
} else { } else {
self.setState({ traceLength: length }) self.setState({ traceLength: length })
self.changeState(0)
} }
}) })
}, },
...@@ -74,7 +75,6 @@ module.exports = React.createClass({ ...@@ -74,7 +75,6 @@ module.exports = React.createClass({
return return
} }
this.changeState(step) this.changeState(step)
this.props.onStepChanged(step)
}, },
stepIntoForward: function () { stepIntoForward: function () {
...@@ -87,7 +87,6 @@ module.exports = React.createClass({ ...@@ -87,7 +87,6 @@ module.exports = React.createClass({
} }
this.refs.slider.setValue(step) this.refs.slider.setValue(step)
this.changeState(step) this.changeState(step)
this.props.onStepChanged(step)
}, },
stepIntoBack: function () { stepIntoBack: function () {
...@@ -100,7 +99,6 @@ module.exports = React.createClass({ ...@@ -100,7 +99,6 @@ module.exports = React.createClass({
} }
this.refs.slider.setValue(step) this.refs.slider.setValue(step)
this.changeState(step) this.changeState(step)
this.props.onStepChanged(step)
}, },
stepOverForward: function () { stepOverForward: function () {
...@@ -110,7 +108,7 @@ module.exports = React.createClass({ ...@@ -110,7 +108,7 @@ module.exports = React.createClass({
var step = this.context.traceManager.findStepOverForward(this.state.currentStepIndex) var step = this.context.traceManager.findStepOverForward(this.state.currentStepIndex)
this.refs.slider.setValue(step) this.refs.slider.setValue(step)
this.changeState(step) this.changeState(step)
this.props.onStepChanged(step)
}, },
stepOverBack: function () { stepOverBack: function () {
...@@ -120,24 +118,23 @@ module.exports = React.createClass({ ...@@ -120,24 +118,23 @@ module.exports = React.createClass({
var step = this.context.traceManager.findStepOverBack(this.state.currentStepIndex) var step = this.context.traceManager.findStepOverBack(this.state.currentStepIndex)
this.refs.slider.setValue(step) this.refs.slider.setValue(step)
this.changeState(step) this.changeState(step)
this.props.onStepChanged(step)
}, },
jumpToNextCall: function () { jumpToNextCall: function () {
if (!this.context.traceManager.isLoaded()) { if (!this.context.traceManager.isLoaded()) {
return return
} }
var step = this.context.traceManager.findNextCall(this.state.currentStepIndex) var step = this.context.traceManager.findNextCall(this.state.currentStepIndex)
this.refs.slider.setValue(step) this.refs.slider.setValue(step)
this.changeState(step) this.changeState(step)
this.props.onStepChanged(step)
}, },
changeState: function (step) { changeState: function (step) {
this.updateGlobalSelectedItem(step) this.updateGlobalSelectedItem(step)
this.setState({ this.setState({
currentStepIndex: step currentStepIndex: step
}) })
this.refs.buttons.stepChanged(step) this.refs.buttons.stepChanged(step)
this.props.onStepChanged(step)
} }
}) })
...@@ -8,12 +8,6 @@ module.exports = React.createClass({ ...@@ -8,12 +8,6 @@ module.exports = React.createClass({
root: React.PropTypes.object root: React.PropTypes.object
}, },
getDefaultProps: function () {
return {
currentStepIndex: -1
}
},
getInitialState: function () { getInitialState: function () {
return { return {
step: '', step: '',
......
...@@ -10,12 +10,6 @@ module.exports = React.createClass({ ...@@ -10,12 +10,6 @@ module.exports = React.createClass({
root: React.PropTypes.object root: React.PropTypes.object
}, },
getDefaultProps: function () {
return {
currentStepIndex: -1
}
},
getInitialState: function () { getInitialState: function () {
return { return {
data: null data: null
......
...@@ -4,6 +4,5 @@ module.exports = { ...@@ -4,6 +4,5 @@ module.exports = {
for (var property in source) { for (var property in source) {
destination[property] = source[property] destination[property] = source[property]
} }
// return destination
} }
} }
...@@ -10,12 +10,6 @@ var StackPanel = require('./stackPanel') ...@@ -10,12 +10,6 @@ var StackPanel = require('./stackPanel')
var StoragePanel = require('./storagePanel') var StoragePanel = require('./storagePanel')
module.exports = React.createClass({ module.exports = React.createClass({
getDefaultProps: function () {
return {
currentStepIndex: -1 // index of the selected item in the vmtrace
}
},
render: function () { render: function () {
return ( return (
<div style={this.props.vmTrace === null ? style.hidden : style.display}> <div style={this.props.vmTrace === null ? style.hidden : style.display}>
...@@ -24,29 +18,29 @@ module.exports = React.createClass({ ...@@ -24,29 +18,29 @@ module.exports = React.createClass({
<tbody> <tbody>
<tr> <tr>
<td> <td>
<ASMCode ref='asmcode' currentStepIndex={this.props.currentStepIndex} /> <ASMCode />
<div style={Object.assign(style.inline, style.sticker)}> <div style={Object.assign(style.inline, style.sticker)}>
<Sticker currentStepIndex={this.props.currentStepIndex} /> <Sticker />
</div> </div>
</td> </td>
<td> <td>
<StackPanel currentStepIndex={this.props.currentStepIndex} /> <StackPanel />
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<StoragePanel currentStepIndex={this.props.currentStepIndex} /> <StoragePanel />
</td> </td>
<td> <td>
<MemoryPanel currentStepIndex={this.props.currentStepIndex} /> <MemoryPanel />
</td> </td>
</tr> </tr>
<tr> <tr>
<td> <td>
<CalldataPanel currentStepIndex={this.props.currentStepIndex} /> <CalldataPanel />
</td> </td>
<td> <td>
<CallstackPanel currentStepIndex={this.props.currentStepIndex} /> <CallstackPanel />
</td> </td>
</tr> </tr>
</tbody> </tbody>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment