-
Notifications
You must be signed in to change notification settings - Fork 706
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
Week4 #40
Week4 #40
Conversation
Week1 version1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, the main thing is that you're not using <Provider>
and @inject
. Otherwise good!
todo-app/src/TodoItem.js
Outdated
import './index.css'; | ||
|
||
|
||
@observer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to make the TodoItem
component a MobX-observer? TodoItem
is not getting its data directly from the store, only from its props, so you don't need to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I need that, 'deleteTodo' and 'changeStatus' do not functioning otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #38 and Ji's detailed explanation here.
todo-app/src/TodoList.js
Outdated
import {observer} from 'mobx-react'; | ||
import {todoStore} from './stores'; | ||
|
||
@observer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget: in the recent version of mobx-react
you need to also add @inject
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added :)
todo-app/src/TodoList.js
Outdated
}; | ||
|
||
onDelete = (todoID) => { | ||
todoStore.onDelete(todoID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small thing: todoStore.onDelete
is not an event handler, but a method on todoStore
. Best to just call it delete
or deleteTodo
.
todo-app/src/TodoList.js
Outdated
} | ||
|
||
onDone = (todoID) => { | ||
todoStore.onDone(todoID); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
</div> | ||
<ul> | ||
{todoStore.todos.map((todoItem, i) => ( | ||
<React.Fragment key={todoItem.id}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to use a Fragment
here, as there's only one child. You can just render the <TodoItem>
directly.
todo-app/src/stores/TodoStore.js
Outdated
} | ||
|
||
@action | ||
onDelete(todoID){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on naming above.
todo-app/src/stores/TodoStore.js
Outdated
} | ||
|
||
@action | ||
onDone(todoID){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on naming above.
todo-app/src/stores/TodoStore.js
Outdated
this.todos.push(todo); | ||
} | ||
|
||
@action |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! This is an action method, and you're correct to mark it as such.
I have changed some after your comments. |
Sorry for late. I had very busy week.