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
10
/**
11
* This component operates as a "Controller-View". It listens for changes in
12
* the TodoStore and passes the new data to its children.
13
*/
14
15
var Footer = require('./Footer.react');
16
var Header = require('./Header.react');
17
var MainSection = require('./MainSection.react');
18
var React = require('react');
19
var TodoStore = require('../stores/TodoStore');
20
21
/**
22
* Retrieve the current TODO data from the TodoStore
23
*/
24
function getTodoState() {
25
return {
26
allTodos: TodoStore.getAll(),
27
areAllComplete: TodoStore.areAllComplete()
28
};
29
}
30
31
var TodoApp = React.createClass({
32
33
getInitialState: function() {
34
return getTodoState();
35
},
36
37
componentDidMount: function() {
38
TodoStore.addChangeListener(this._onChange);
39
},
40
41
componentWillUnmount: function() {
42
TodoStore.removeChangeListener(this._onChange);
43
},
44
45
/**
46
* @return {object}
47
*/
48
render: function() {
49
return (
50
<div>
51
<Header />
52
<MainSection
53
allTodos={this.state.allTodos}
54
areAllComplete={this.state.areAllComplete}
55
/>
56
<Footer allTodos={this.state.allTodos} />
57
</div>
58
);
59
},
60
61
/**
62
* Event handler for 'change' events coming from the TodoStore
63
*/
64
_onChange: function() {
65
this.setState(getTodoState());
66
}
67
68
});
69
70
module.exports = TodoApp;
71
72