Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/actions/action-types.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Use "todos/CHECK_TODO",
// it is just good practice.
// When we have more than a single reducer
// working, we can quickly tell what reducer
// an action belongs to (and avoid conflicts).
export const CHECK_TODO = "CHECK_TODO"
export const ADD_TODO = "ADD_TODO"
export const REMOVE_TODO = "REMOVE_TODO"
10 changes: 10 additions & 0 deletions app/actions/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
// I think the index file should just
// import stuff and export stuff.
// Move this to an actions.js file.

// import * as t, and you can
// access the members as t.CHECK_TODO
// for example. This way you can
// protect the global namespace and keep it clean.
import {
CHECK_TODO,
ADD_TODO,
REMOVE_TODO
} from './action-types';

// This should come as the first statement in file.
"use strict";

export const checkTodo = (todo) => {
Expand Down
1 change: 1 addition & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import TodoList from 'components/todos-list';
import NewTodoInput from 'components/new-todo-input';

// Very clean code!
const App = () => (
<div>
<NewTodoInput />
Expand Down
8 changes: 8 additions & 0 deletions app/components/new-todo-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import { addTodo} from '../actions/index';

// The way to avoid using document.getElementById and acessing the DOM
// directly is to add an event handler to <input/> and use a local state.
// Something like:
// <input onChange={(event) => this.setState({newTodoText: event.target.value})}
// You can also make it go through Redux here,
// but local state is not always evil,
// specially in this case
// where you are just storing the value from a form field.
class NewTodoInput extends Component{

keyPressHandler(e){
Expand Down
8 changes: 8 additions & 0 deletions app/components/todos-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import {delTodo, checkTodo} from '../actions/index';

// Extract the code inside map to a TodoListItem component.
// Pass each todo as a prop to the Item component.
// This will also simplify your code and you'll be able
// to put all render code inside render().
// It will be simpler. Instead of having
// a method return all items,
// iterate on render().

class TodoList extends Component{

createListItems(){
Expand Down
3 changes: 3 additions & 0 deletions app/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Redux from 'redux';
import ReactDOM from 'react-dom';
import {start} from './todos'

// Put the code from todos.js here.
// No need to have two files doing pretty much
// the same.
document.addEventListener('DOMContentLoaded', () => {
start();
});
4 changes: 4 additions & 0 deletions app/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import {Provider} from 'react-redux';
import Reducer from 'reducers/reducer'
import App from 'app';

// Move this to initialize, that makes
// more sense don't you think?
export function start () {
const store = createStore(Reducer);

// Reformat, it looks weird with the
// comma on its own big line. Use ESLint.
ReactDOM.render(
<Provider store = {store}>
<App />
Expand Down