Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80684 views
1
/*
2
* Copyright (c) 2014-2015, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* TodoActions
10
*/
11
12
var AppDispatcher = require('../dispatcher/AppDispatcher');
13
var TodoConstants = require('../constants/TodoConstants');
14
15
var TodoActions = {
16
17
/**
18
* @param {string} text
19
*/
20
create: function(text) {
21
AppDispatcher.dispatch({
22
actionType: TodoConstants.TODO_CREATE,
23
text: text
24
});
25
},
26
27
/**
28
* @param {string} id The ID of the ToDo item
29
* @param {string} text
30
*/
31
updateText: function(id, text) {
32
AppDispatcher.dispatch({
33
actionType: TodoConstants.TODO_UPDATE_TEXT,
34
id: id,
35
text: text
36
});
37
},
38
39
/**
40
* Toggle whether a single ToDo is complete
41
* @param {object} todo
42
*/
43
toggleComplete: function(todo) {
44
var id = todo.id;
45
var actionType = todo.complete ?
46
TodoConstants.TODO_UNDO_COMPLETE :
47
TodoConstants.TODO_COMPLETE;
48
49
AppDispatcher.dispatch({
50
actionType: actionType,
51
id: id
52
});
53
},
54
55
/**
56
* Mark all ToDos as complete
57
*/
58
toggleCompleteAll: function() {
59
AppDispatcher.dispatch({
60
actionType: TodoConstants.TODO_TOGGLE_COMPLETE_ALL
61
});
62
},
63
64
/**
65
* @param {string} id
66
*/
67
destroy: function(id) {
68
AppDispatcher.dispatch({
69
actionType: TodoConstants.TODO_DESTROY,
70
id: id
71
});
72
},
73
74
/**
75
* Delete all the completed ToDos
76
*/
77
destroyCompleted: function() {
78
AppDispatcher.dispatch({
79
actionType: TodoConstants.TODO_DESTROY_COMPLETED
80
});
81
}
82
83
};
84
85
module.exports = TodoActions;
86
87