Skip to content

Commit 6336102

Browse files
committed
Firebase - Section 8
1 parent 65eae7c commit 6336102

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

todos/src/app.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ var React = require('react');
22
var ReactFire = require('reactfire');
33
var Firebase = require('firebase');
44
var Header = require('./header');
5+
var List = require('./list');
56
var rootUrl = 'https://blistering-torch-4253.firebaseio.com/';
67

78
var App = React.createClass({
89
mixins: [ ReactFire ],
10+
getInitialState: function() {
11+
return {
12+
items: {}
13+
}
14+
},
915
componentWillMount: function() {
1016
this.bindAsObject(new Firebase(rootUrl + 'items/'), 'items');
1117
},
@@ -16,6 +22,7 @@ var App = React.createClass({
1622
To-Do List
1723
</h2>
1824
<Header itemsStore={this.firebaseRefs.items} />
25+
<List items={this.state.items} />
1926
</div>
2027
</div>
2128
}

todos/src/list.jsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
var React = require('react');
2+
3+
module.exports = React.createClass({
4+
render: function() {
5+
return <ul>
6+
{this.renderList()}
7+
</ul>
8+
},
9+
renderList: function() {
10+
if(this.props.items && Object.keys(this.props.items).length === 0) {
11+
return <h4>
12+
Add a todo to get started.
13+
</h4>
14+
} else {
15+
var children = [];
16+
17+
for(var key in this.props.items) {
18+
children.push(
19+
<li>
20+
{this.props.items[key].text}
21+
</li>
22+
)
23+
}
24+
25+
return children;
26+
}
27+
}
28+
});

0 commit comments

Comments
 (0)