Skip to content

Commit d607370

Browse files
extracted constants to constants
1 parent 5a29f67 commit d607370

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

ep28-more-dispatcher-usage/app/actions/TodoActions.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var api = require("../utils/api");
22
var TodoStore = require("../stores/TodoStore");
33
var AppDispatcher = require('../dispatcher/AppDispatcher');
4+
var Constants = require("../utils/constants");
45

56
var TodoActions = {
67

@@ -15,7 +16,7 @@ var TodoActions = {
1516
api.deleteTodo(todo.id)
1617
.then( () => {
1718
AppDispatcher.dispatch({
18-
actionType: 'TODO_DELETE',
19+
actionType: Constants.TODO_DELETE,
1920
todo: todo
2021
});
2122
})
@@ -25,7 +26,7 @@ var TodoActions = {
2526
api.markTodoDone(todo)
2627
.then( () => {
2728
AppDispatcher.dispatch({
28-
actionType: 'TODO_DONE',
29+
actionType: Constants.TODO_DONE,
2930
todo: todo
3031
});
3132

@@ -36,7 +37,7 @@ var TodoActions = {
3637
api.markTodoUnDone(todo)
3738
.then( () => {
3839
AppDispatcher.dispatch({
39-
actionType: 'TODO_UNDONE',
40+
actionType: Constants.TODO_UNDONE,
4041
todo: todo
4142
});
4243
})
@@ -48,7 +49,7 @@ var TodoActions = {
4849
var todos = responseData.todos;
4950
TodoStore.setTodos(todos);
5051
AppDispatcher.dispatch({
51-
actionType: 'TODO_ADD'
52+
actionType: Constants.TODO_ADD
5253
});
5354
})
5455
}

ep28-more-dispatcher-usage/app/stores/TodoStore.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
var AppDispatcher = require('../dispatcher/AppDispatcher');
2+
var Constants = require("../utils/constants");
23

34
AppDispatcher.register(function(action) {
45

56
switch(action.actionType) {
6-
case 'TODO_DONE':
7+
case Constants.TODO_DONE:
78
TodoStore.markTodoDone(action.todo);
89
break;
910

10-
case 'TODO_UNDONE':
11+
case Constants.TODO_UNDONE:
1112
TodoStore.markTodoUnDone(action.todo);
1213
break;
1314

14-
case 'TODO_DELETE':
15+
case Constants.TODO_DELETE:
1516
TodoStore.deleteTodo(action.todo);
1617
break;
1718

18-
case 'TODO_ADD':
19+
case Constants.TODO_ADD:
1920
TodoStore.getTodos();
2021
break;
2122
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
var Constants = {
22
BASE_URL: "http://lrjis-api-production.herokuapp.com/api/v1/",
3-
API_KEY: "4d5e466a-97a4-46ba-bb3d-3da6c4347965"
3+
API_KEY: "4d5e466a-97a4-46ba-bb3d-3da6c4347965",
4+
TODO_DONE: 'TODO_DONE',
5+
TODO_UNDONE: 'TODO_UNDONE',
6+
TODO_DELETE: 'TODO_DELETE',
7+
TODO_ADD: 'TODO_ADD'
48
};
59
module.exports = Constants;

0 commit comments

Comments
 (0)