Hello Nathan,
After reading some about redux-react stuffs, I just realized it may rerender your app if your state comes with shallow object change.
Let say pop and push over an array won’t make a new array object, instead it changes the state of the array.
You code part is about pop the last operator and push new one won’t trigger react-redux render.
I just came up with following, and it looks working, please check:
TIP: think about a way to push new array, instead of changing existing array.
...
if (ops.includes(state.eq[state.eq.length - 1]) && state.currNum === "") {
stateHold.eq.pop();
stateHold.eq.push(action.opStr);
return {
currNum: "",
//eq: stateHold.eq
eq: stateHold.eq.slice(0,stateHold.eq.length)
};
...
I also found a very bad bug which is about the way it calculates(eval
call), if you just ask for 36 - 6
it will result 3
! I think this is becasue of bug with your redundZero
. You should just remove the zero from floating part.
Following
if (str[index]==='0' || str[index]==='.'){
index--;
continue;
}
Is faulty, please note once you reach the dot (.) (and probably becasue all float parts were zero), you should go one more index--
and break, becasue rest zeros(at left side) are required. (quick math ), please fix it.
I also two suggestions.
0) please make it possible to work with keyboard, it’s much easier to work with a calc with keyboard, rather mouse click.
- Once user enters an operator (+, - , …) have small place to show the previous operators, and values in queue somewhere, this helps so much.
Keep going on great work comrade, happy programming.