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

Update TodoMVC example to be more in line with other examples #2757

Merged
merged 5 commits into from
Apr 9, 2018

Conversation

tomipaul
Copy link
Contributor

  • Store visibilityFilter in the state
  • Update presentational components
  • Add container components
  • Update reducer code to use composition
  • Add Reselect

@timdorr
Copy link
Member

timdorr commented Dec 22, 2017

Sorry I haven't had a chance to look at this. It's fairly extensive, so it may take some time. If others want to make some review comments, go right ahead. I'm not the sole gate keeper for contributions to this project 😄

Copy link
Contributor

@raunofreiberg raunofreiberg left a comment

Choose a reason for hiding this comment

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

Some general comments about code styling, conventions and consistency. Maybe this'll get this PR moving :)

return (
<section className="main">
{
(todosCount > 0) ?
Copy link
Contributor

@raunofreiberg raunofreiberg Feb 21, 2018

Choose a reason for hiding this comment

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

How about doing !!todosCount && <Component ... /> instead of the ternary? Would also get rid of the null being returned if the condition is not met.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, thanks

import VisibleTodoList from '../containers/VisibleTodoList'

const MainSection = (props) => {
const { todosCount, completedCount, actions } = props
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just destructure these inside the parameters of the function and have an implicit return.

}
<VisibleTodoList />
{
(todosCount > 0) ?
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.

)}
</ul>
{
(completedCount > 0) ?
Copy link
Contributor

@raunofreiberg raunofreiberg Feb 21, 2018

Choose a reason for hiding this comment

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

Ditto for the ternary above.

@@ -4,5 +4,6 @@ export const addTodo = text => ({ type: types.ADD_TODO, text })
export const deleteTodo = id => ({ type: types.DELETE_TODO, id })
export const editTodo = (id, text) => ({ type: types.EDIT_TODO, id, text })
export const completeTodo = id => ({ type: types.COMPLETE_TODO, id })
export const completeAll = () => ({ type: types.COMPLETE_ALL })
export const completeAllTodos = () => ({ type: types.COMPLETE_ALL_TODOS })
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the rename? Seems like the context is obvious here regardless.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is obvious. I just feel having Todos attached to the completeAll will make it much more explicit and consistent with the others.

import classnames from 'classnames'

const Link = ({ active, children, setFilter }) => {
return (
Copy link
Contributor

Choose a reason for hiding this comment

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

Use an implicit return. No need for the block.

mapDispatchToProps
)(Link)

export default FilterLink
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer doing

export default connect(
   mapStateToProps,
   mapDispatchToProps
)(Link)

But I'm not sure if this is a convention or not, I just don't see the point in the intermediary variable that is disposable anyway.

addTodo: PropTypes.func.isRequired
}

export default connect(null, { addTodo })(Header)
Copy link
Contributor

Choose a reason for hiding this comment

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

Even more reasons to use the convention described above then if this is already in use here.

import { getCompletedTodoCount } from '../selectors'


const mapStateToProps = (state) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like in some cases you're using an implicit return for an object and in some cases an explicit one. I would recommend keeping it consistent and using an implicit return in all cases then, unless you require a block for extra statements.

@timdorr
Copy link
Member

timdorr commented Mar 13, 2018

@tomipaul Any chance you can address those comments and also resolve the merge conflicts?

@tomipaul
Copy link
Contributor Author

tomipaul commented Apr 8, 2018

Oops Somehow I missed your comment @timdorr

Back when the comments were made, I started addressing them before some other work took me off.
I will just complete it and fix the conflict
In the next 24 hours, the PR should look good.

Add action to set visibility filter
Change COMPLETE_ALL to COMPLETE_ALL_TODOS
handle set_visibility_filter action
store visibilityFilter in the state
update complete_all to complete_all_todos
update reducer code to use composition
Add a root App component
Add a link component to select visibility filter
Add a todolist component to display todos
Refactor mainsection and footer to functional components
add containers for link, header, mainsection and todolist
add Reselect
@tomipaul
Copy link
Contributor Author

tomipaul commented Apr 9, 2018

@timdorr I'm done with the fixes.
However, the Travis build is failing at the todos-flow example test.
I think it's a problem with the flow-typed dependency
If that is resolved, this PR should be completely fine.

@timdorr
Copy link
Member

timdorr commented Apr 9, 2018

That should be fixed in master now too. Waiting on a build to confirm that and then I'll merge this in. Thanks for keeping up with this!

@timdorr timdorr merged commit 99d47a5 into reduxjs:master Apr 9, 2018
@tomipaul
Copy link
Contributor Author

tomipaul commented Apr 9, 2018

Thanks, it was fun all along.

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.

None yet

3 participants