File tree 3 files changed +18
-12
lines changed 3 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -4,16 +4,22 @@ var AppDispatcher = require('../dispatcher/AppDispatcher');
4
4
5
5
var TodoActions = {
6
6
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
+
7
18
addTodo : ( todo ) => {
8
19
console . log ( "adding TODO" ) ;
9
20
api . addTodo ( todo )
10
21
. 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 ( ) ;
17
23
} )
18
24
. then ( ( ) => {
19
25
console . log ( "Added TODO successfully" ) ;
Original file line number Diff line number Diff line change @@ -28,12 +28,7 @@ export default class App extends React.Component {
28
28
}
29
29
30
30
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 ( ) ;
37
32
}
38
33
39
34
handleClearCompleted ( event ) {
Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ AppDispatcher.register(function(action) {
24
24
console . log ( "Handling TODO_ADD using dispatcher in store" ) ;
25
25
TodoStore . getTodos ( ) ;
26
26
break ;
27
+
28
+ case 'TODO_ALL' :
29
+ console . log ( "Handling TODO_ALL using dispatcher in store" ) ;
30
+ TodoStore . setTodos ( action . todos ) ;
31
+ break ;
27
32
}
28
33
29
34
} ) ;
You can’t perform that action at this time.
0 commit comments