Skip to content

Commit 791d101

Browse files
TODO_ALL action
1 parent 971c2cf commit 791d101

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

ep30-extract-form-into-componenet-from-app/app/actions/TodoActions.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ var AppDispatcher = require('../dispatcher/AppDispatcher');
44

55
var TodoActions = {
66

7+
allTodos: () => {
8+
api.getTodos()
9+
.then( (responseData) => {
10+
console.log("Got All TODOs successfully");
11+
AppDispatcher.dispatch({
12+
actionType: 'TODO_ALL',
13+
todos: todos
14+
});
15+
})
16+
},
17+
718
addTodo: (todo) => {
819
console.log("adding TODO");
920
api.addTodo(todo)
1021
.then( () => {
11-
api.getTodos()
12-
.then( (responseData) => {
13-
var todos = responseData.todos;
14-
console.log("All todos", todos);
15-
TodoStore.setTodos(todos);
16-
})
22+
allTodos();
1723
})
1824
.then( () => {
1925
console.log("Added TODO successfully");

ep30-extract-form-into-componenet-from-app/app/components/App.jsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@ export default class App extends React.Component {
2828
}
2929

3030
getAllTodos () {
31-
api.getTodos()
32-
.then( (responseData) => {
33-
var todos = responseData.todos;
34-
this.setState({todos: todos });
35-
TodoStore.setTodos(todos);
36-
})
31+
TodoActions.allTodos();
3732
}
3833

3934
handleClearCompleted (event) {

ep30-extract-form-into-componenet-from-app/app/stores/TodoStore.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ AppDispatcher.register(function(action) {
2424
console.log("Handling TODO_ADD using dispatcher in store");
2525
TodoStore.getTodos();
2626
break;
27+
28+
case 'TODO_ALL':
29+
console.log("Handling TODO_ALL using dispatcher in store");
30+
TodoStore.setTodos(action.todos);
31+
break;
2732
}
2833

2934
});

0 commit comments

Comments
 (0)