Cool, it looks pretty cool.
If I look at the code and put on my nitpicking capβ¦
Your JS formatting is really nonstandard. It would be a lot easier to learn some of the basics of common formatting - it will make it easier to blend into a team. I had trouble reading it and had to run it through a formatter:
const cState = (obj) => Object.assign({}, state, obj);
OK, but why not just use ES6 practices like instead of:
return cState({ formula: "0", result: "0" });
do
return { ...state, formula: "0", result: "0" };
That would be much more common.
That entire reducer is kind of messy. I hate nested switch statements unless they are so small as to be easily digested visually - this is not. I would probably break those first level cases into helper functions. I might even do the same for the inner switch. And that inner switch lacks a default, which is done manually.
I see a lot of cryptic names in here: cState, frmla, action.n, propys - those may make sense to you but they will be confusing to a different developer, which includes you if youβre looking at your code after 6 months.
mapS2P and mapD2P - spell them out, like is the industry standard.
Also, these could be simplified to:
const mapStateToProps = ({ formula, result }) => ({
formula,
result,
});
const mapDispatchToProps = {
handleClick: getFormula,
};
Notice that mapDispatchToProps is now an object instead of a function. I know itβs taught as a function, but this is much more common in my experience.
But still good job. Have fun on the next one.
Thank you very much for taking your time to critique my work, it means a lot!
about this one, how about the dispatch method?
AWESOME!
How did you implement the infinite operations thing.
If you send it an object and it is a standard usage, it figures it out, behind the scenes. Check out the docs.
Can you explain more please ?
Sorry. I mean how did u implement, multiple operations.
Not just x - y or y + x etc.
Is there like a function.
Or did you implement it urself.
you put the expression inside eval("here"), and Javascript does the calculation.
ex:
eval("5*3+12") // returns 27
but MDN says :
Warning: Executing JavaScript from a string is an enormous security risk. It is far too easy for a bad actor to run arbitrary code when you use
eval(). See Never use eval()!, below.
So i changed eval with Function, like that:
Function('"use strict";return (5*3+12)')() // returns 27.
Oh! Thanks a lot!
eval is present in Python as well.
Thanks again!!!
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.