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
+ const numberRows = expr.numbers.map((n, i) =>
);
+ console.log('Numbers: ', expr.numbers);
+ return
+
+ !{expr.toString()}!
+
+
+
}
}
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