diff --git a/src/app/cmd.js b/src/app/cmd.js index c7017b0..eb44168 100644 --- a/src/app/cmd.js +++ b/src/app/cmd.js @@ -59,7 +59,6 @@ var cmd = { } function invokeHandler (input, handler) { - console.log('[invokeHandler]: ' + input); var cmdResult = handler.handle({ input: input}); if(cmdResult != null) { console.log(cmdResult); diff --git a/src/app/commands.js b/src/app/commands.js index 24839a6..9afcb65 100644 --- a/src/app/commands.js +++ b/src/app/commands.js @@ -13,7 +13,6 @@ export default { canHandle: (input) => expression.parser.canParse(input), handle: function(c) { var expr = expression.parser.parse(c.input); - console.log(expr); appState.addCommandResult(new ExpressionResult(c.input, expr)); } }) diff --git a/src/app/components/AppRoot.jsx b/src/app/components/AppRoot.jsx index 5a0d4c2..ce768de 100644 --- a/src/app/components/AppRoot.jsx +++ b/src/app/components/AppRoot.jsx @@ -12,6 +12,8 @@ export default class AppRoot extends React.Component { this.setState(this.props.appState); } render() { + console.log('[AppRoot] render():this.state.commandResults', this.state.commandResults) + var results = this.state.commandResults.map((r, i) => ); return
diff --git a/src/app/components/results/ExpressionResultView.jsx b/src/app/components/results/ExpressionResultView.jsx index 3ccf546..abdd573 100644 --- a/src/app/components/results/ExpressionResultView.jsx +++ b/src/app/components/results/ExpressionResultView.jsx @@ -5,8 +5,12 @@ import * as expression from '../../expression'; export default class ExpressionResultView extends React.Component { render() { var expr = this.props.result.expression; + if(expr instanceof expression.ListOfNumbersExpression) { - return + return
+ Expression: {expr.expressionString} + +
} return Expression: {expr.expressionString}; diff --git a/src/app/components/results/ListOfNumbersExpressionView.jsx b/src/app/components/results/ListOfNumbersExpressionView.jsx index f687777..d180bd3 100644 --- a/src/app/components/results/ListOfNumbersExpressionView.jsx +++ b/src/app/components/results/ListOfNumbersExpressionView.jsx @@ -4,35 +4,47 @@ import formatter from '../../formatter'; export default class ListOfNumersExpressionView extends React.Component { render() { const expr = this.props.expression; - const numberViews = expr.numbers.map((n, i) => ) - return - {numberViews} -
+ const numberRows = expr.numbers.map((n, i) => ); + console.log('Numbers: ', expr.numbers); + return
+
+ !{expr.toString()}! +
+ + + {numberRows} + +
+
} } class OperandView extends React.Component { - componentWillMount() { - this.setState(this.props.operand); - } + constructor() { + super(); + this.state = { operand: null }; + } render() { - const op = this.state; + const op = this.props.operand; const binaryString = formatter.padLeft(op.bin, this.props.maxBitsLegnth, '0'); return - {op.input} - this.flipBit(i)} /> - {op.other} - + {op.input} + this.flipBit(e)} /> + {op.other} + ; }; flipBit(index) { var op = this.props.operand; const binaryString = formatter.padLeft(op.bin, this.props.maxBitsLegnth, '0'); var arr = binaryString.split(''); + // TODO: this code looks ugly arr[index] = arr[index] == '0' ? '1' : '0'; - op.update(arr.join('')); - this.setState(op); + var bin = arr.join(''); + op.setValue(parseInt(bin, 2)); + + this.setState({ operand: op }); } } diff --git a/src/app/expression.js b/src/app/expression.js index d20d9c1..95ac769 100644 --- a/src/app/expression.js +++ b/src/app/expression.js @@ -134,7 +134,7 @@ export class Operand { getOtherKind(kind) { - switch(kind) { + switch(kind || this.kind) { case 'dec': return 'hex'; case 'hex': return 'dec'; default : throw new Error(kind + " kind doesn't have opposite kind") @@ -145,11 +145,15 @@ export class Operand { return this.input; } - update(binary) { - this.value = parseInt(2); - this.bin = binary; + setValue(value) { + console.log('Before ' + value, this); + this.value = value; + this.bin = Operand.toKindString(this.value, 'bin'); this.dec = Operand.toKindString(this.value, 'dec'); this.hex = Operand.toKindString(this.value, 'hex'); + this.other = Operand.toKindString(this.value, this.getOtherKind()); + this.input = Operand.toKindString(this.value, this.kind); + console.log('After ' + value, this); } static getBitLength(num) { @@ -241,6 +245,10 @@ export class ListOfNumbersExpression { this.numbers = numbers; this.maxBitsLegnth = _.chain(numbers).map(n => n.lengthInBits).reduce((n , c) => n >= c ? n : c, 0).value(); } + + toString() { + return this.numbers.map(n => n.value.toString()).join(' '); + } } export class Expression { diff --git a/src/app/index.jsx b/src/app/index.jsx index b020058..ec9d955 100644 --- a/src/app/index.jsx +++ b/src/app/index.jsx @@ -8,9 +8,9 @@ import AppRoot from './components/AppRoot'; commands.initialize(cmd); -cmd.execute('1'); -cmd.execute('2'); -cmd.execute('3'); +// cmd.execute('1'); +// cmd.execute('2'); +// cmd.execute('3'); var root = ; ReactDOM.render(root, document.getElementById('root')); \ No newline at end of file