-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (31 loc) · 1.11 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
var React = require('react/addons');
var Freighter = require('./../src/index');
var HelloWorldStore = require('./stores/HelloWorldStore');
var HelloWorldActionCreator = require('./actions/HelloWorldActionCreator');
var HelloWorld = React.createClass({
mixins: [Freighter],
stores: [HelloWorldStore],
getStateFromStores: function(){
return HelloWorldStore.getDataFromStore();
},
handleSubmit: function(e){
e.preventDefault();
//There are better ways to handle forms :)
var age = this.refs.age.getDOMNode().value.trim();
HelloWorldActionCreator.updateAge(React.addons.update(this.state, {$merge: {age: age}}));
this.refs.age.getDOMNode().value = '';
},
render: function () {
return (
<div>
<p>Hello {this.state.name}, I am {this.state.age ? this.state.age : '__blank__'} years old.</p>
<form onSubmit={this.handleSubmit}>
<input placeholder="age" type="text" name="age" ref="age" />
<button type="submit">Submit</button>
</form>
</div>
);
}
});
React.render(<HelloWorld />, document.getElementById('example'));