Skip to content

Commit

Permalink
Firebase - Section 8
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jun 4, 2015
1 parent 65eae7c commit 6336102
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions todos/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ var React = require('react');
var ReactFire = require('reactfire');
var Firebase = require('firebase');
var Header = require('./header');
var List = require('./list');
var rootUrl = 'https://blistering-torch-4253.firebaseio.com/';

var App = React.createClass({
mixins: [ ReactFire ],
getInitialState: function() {
return {
items: {}
}
},
componentWillMount: function() {
this.bindAsObject(new Firebase(rootUrl + 'items/'), 'items');
},
Expand All @@ -16,6 +22,7 @@ var App = React.createClass({
To-Do List
</h2>
<Header itemsStore={this.firebaseRefs.items} />
<List items={this.state.items} />
</div>
</div>
}
Expand Down
28 changes: 28 additions & 0 deletions todos/src/list.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var React = require('react');

module.exports = React.createClass({
render: function() {
return <ul>
{this.renderList()}
</ul>
},
renderList: function() {
if(this.props.items && Object.keys(this.props.items).length === 0) {
return <h4>
Add a todo to get started.
</h4>
} else {
var children = [];

for(var key in this.props.items) {
children.push(
<li>
{this.props.items[key].text}
</li>
)
}

return children;
}
}
});

0 comments on commit 6336102

Please sign in to comment.