Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code review #1

Open
wants to merge 39 commits into
base: initial
Choose a base branch
from
Open

Code review #1

wants to merge 39 commits into from

Conversation

larsbs
Copy link

@larsbs larsbs commented May 7, 2019

No description provided.

Copy link
Author

@larsbs larsbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First code review

NOTE: Sometimes, when the same issue appears duplicated, not always a comment has been made. That shouldn't prevent the issue from being fixed. E.g: arrow function parentheses.

A few tasks and a challenge one to be done after the review has been taken into account:

Tasks:

  • Use react-hooks as mentioned in the review.
  • Port the styles of the app to emotion.

Challenge:

NOTE 2: Please, ask questions, we're not in the examining phase anymore, now we're in the learning phase ;)

@@ -0,0 +1,33 @@
{
"name": "groceries-app-react",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use spaces instead of tabs for indenting code. Specifically, two spaces.

@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary space

const Button = ({ children, secondary, ...props }) => {
const buttonClass = secondary ? styles.secondary : styles.button;
return (
<>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use <Fragment></Fragment> instead of <></>. That way it looks more consistent with the rest of the code.

};

Button.defaultProps = {
secondary: null,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only define defaultProps when they're needed. In this case, setting secondary to null doesn't change anything. Treat defaultProps as a way of telling the users, "Hey, I really need a value for this in order to work correctly"

Also, defaultProps should correctly reflect the expected type according to propTypes. In this case, a boolean.

font-weight: 500;
background: rgb(0, 83, 135);
border: 2px solid white;
color: white;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistent indentation

const grocery = this.groceryService.addGroceryItem(newItem);

this.setState({
grocery: grocery,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant same key: value. Replace it by this.setState({ grocery })


render() {
const { isModalOpen, formType, itemUnderEdition } = this.state;
const contextElements = {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's cool you considered you don't need Redux, but instead of having a huge AppContext have smaller context that would manage each pice of state separately. E.g: ItemsContext, UIContext, etc... and components would use the one they specifically need.

};

render() {
const { isModalOpen, formType, itemUnderEdition } = this.state;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variables

import styles from './StatisticsView.module.scss';

const StatisticsView = () => (
<>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary Fragment

@@ -0,0 +1,10690 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use yarn. Use npm

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsbs I used both for various projects and yarn seems to be better in a way, that it is caching a lot of libraries, which makes it work faster. Do you have any information that might be interesting for comparison? At company we are using npm?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at company we use npm. And there are various benefits for using npm over yarn (starting from version 5, that's the important thing):

  • Independent tool (yarn is basically backed by fb)
  • Comes with node and you can expect to find it in every other system
  • The newer versions of npm also include a lock file basically removing the biggest different in favor of yarn
  • Better support for compiling native libraries (this was the main reason that made us move away)
  • Using npm ci intead of npm i, the speed difference between yarn and npm is basically none now.
  • And a few more I don't want to continue listing like checking dependencies for vulnerabilities, easier upgrade of dependencies, etc.

yarn used to be "better" than npm but not anymore, so the main gist is, why learn another tool when the default one already does everything?

I hope that helped you

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larsbs Thank you! This is really valuable knowledge! I will read more about changes of the npm itself, but as I have a lot of tasks now, it will be added to my personal backlog :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants