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

Knar - Homework week 5 #231

Closed
wants to merge 2 commits into from
Closed

Knar - Homework week 5 #231

wants to merge 2 commits into from

Conversation

PKnar
Copy link

@PKnar PKnar commented Sep 13, 2018

No description provided.

Copy link

@prof-xed prof-xed left a comment

Choose a reason for hiding this comment

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

Great Job.
Hi @PKnar, you have a nice clean Code, I saw your good understanding of how Mobx is working.

But still no mind from leaving some comments improving a bit more work 🙂

@inject("TodoStore")
@observer
class App extends React.Component {
componentWillMount() {

Choose a reason for hiding this comment

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

as @neveenatik noticed me componentWillMount has been deprecated in 16.3 React for that you can check this.
instead of componentWillMount we may use the constructor or you may find this useful

)
) : (
<List>{todoItems}</List>
);

Choose a reason for hiding this comment

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

I see too much Js with a Jsx inside of the render method...

here we have two things to mention:

  • these have to be consts variables.
  • moving these to a separated component is way less code and easier to follow and debug.

And also I won't forgot to mention about line 35.
you may keep the letin case of a reassign variable to a new Value inside the new value or you could do this:

const NoTodos = () => <p id="no-todos">No todos yet... </p>

const Loading = () => <p id="no-todos">Loading... </p>

const ContentStatus = () => TodoStore.state === "Loading" ? <Loading /> : <NoTodos />

const Content = () => TodoStore.todoCount === 0 ? <ContentStatus /> : <List>{todoItems}</List>

// and inside the return you will have the <Content /> JSX component. 🙂👌

class AddTodoForm extends React.Component {
onAddTodo = e => {
e.preventDefault();
let newTodo = this.enteredTodo.value;

Choose a reason for hiding this comment

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

you are not reassigning the newTodo variable in any other place.
using const is a better thing to have from the code styling and structuring in my case and from the memory usage in other case a will.

onAddTodo = e => {
e.preventDefault();
let newTodo = this.enteredTodo.value;
if (newTodo === "") {

Choose a reason for hiding this comment

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

we could use with the same behavior:

if (!newTodo) return;

import React from "react";
class Checkbox extends React.Component {
render() {
let done = this.props.done;

Choose a reason for hiding this comment

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

const 😃

toggleDone = async id => {
let todoItem = this.todos.find(todo => todo._id === id);
try {
await this.handleFetch(`${url}/todos/${id}`, "PATCH", {

Choose a reason for hiding this comment

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

if you will assign this line to a variable we may have a look to the next comment...

}
return todo;
});
this.todos = todoItems;

Choose a reason for hiding this comment

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

by assigning line 33 to a variable we can use it here instead of all from line 37 till line 46.
let's say the variable name is updated you can choose a better name.

runInAction(() => {
  this.todos = this.todos.map(todo => {
    if (updated._id !== todo._id) return todo;
    return updated
  }) // thats is 🎊
});

@action
addTodo = async newTodo => {
let todoItem = {
id: uuidv4(),

Choose a reason for hiding this comment

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

no need for the uuid use here.
while you are dealing with a server this is just like an extra information you are sending to the server, the server is just handling this for us.

deleteTodo = async id => {
this.state = "Loading";
try {
await this.handleFetch(`${url}/todos/${id}`, "DELETE");

Choose a reason for hiding this comment

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

we are not using a the response data because no need for it 💯 🥇

}
};
@action
updateTodo = async (id, newTodo) => {

Choose a reason for hiding this comment

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

Same as toggleDone method 🙂

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

Successfully merging this pull request may close these issues.

3 participants