Skip to content

Commit a466ecb

Browse files
committed
Firebase - Section 11
1 parent 323226d commit a466ecb

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

todos/src/list-item.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
var React = require('react');
2+
var Firebase = require('firebase');
3+
var rootUrl = 'https://blistering-torch-4253.firebaseio.com/';
24

35
module.exports = React.createClass({
46
getInitialState: function() {
57
return {
6-
text: this.props.item.text
8+
text: this.props.item.text,
9+
done: this.props.item.done
710
}
811
},
12+
componentWillMount: function() {
13+
this.fb = new Firebase(rootUrl + 'items/' + this.props.item.id);
14+
},
915
render: function() {
1016
return <div className="input-group">
1117
<span className="input-group-addon">
12-
<input type="checkbox" />
18+
<input
19+
type="checkbox"
20+
checked={this.state.done}
21+
onChange={this.handleDoneChange}
22+
/>
1323
</span>
1424
<input type="text"
1525
className="form-control"
@@ -21,5 +31,10 @@ module.exports = React.createClass({
2131
</button>
2232
</span>
2333
</div>
34+
},
35+
handleDoneChange: function(event) {
36+
var update = {done: event.target.checked}
37+
this.setState(update);
38+
this.fb.update(update);
2439
}
2540
});

0 commit comments

Comments
 (0)