-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
85 lines (72 loc) · 1.79 KB
/
index.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/** @jsx React.DOM */
require('./index.css');
var React = require('react');
var Router = require('react-router');
var { Route, RouteHandler, Link } = Router;
var App = React.createClass({
mixins: [ Router.Navigation ],
getInitialState: function () {
return {
tacos: [
{ name: 'duck confit' },
{ name: 'carne asada' },
{ name: 'shrimp' }
]
};
},
addTaco: function () {
var name = prompt('taco name?');
this.setState({
tacos: this.state.tacos.concat({name: name})
});
},
handleRemoveTaco: function (removedTaco) {
var tacos = this.state.tacos.filter(function (taco) {
return taco.name != removedTaco;
});
this.setState({tacos: tacos});
this.transitionTo('/');
},
render: function () {
var links = this.state.tacos.map(function (taco, i) {
return (
<li key={i}>
<Link to="taco" params={taco}>{taco.name}</Link>
</li>
);
});
return (
<div className="App">
<button onClick={this.addTaco}>Add Taco</button>
<ul className="Master">
{links}
</ul>
<div className="Detail">
<RouteHandler onRemoveTaco={this.handleRemoveTaco}/>
</div>
</div>
);
}
});
var Taco = React.createClass({
mixins: [ Router.State ],
remove: function () {
this.props.onRemoveTaco(this.getParams().name);
},
render: function () {
return (
<div className="Taco">
<h1>{this.getParams().name}</h1>
<button onClick={this.remove}>remove</button>
</div>
);
}
});
var routes = (
<Route handler={App}>
<Route name="taco" path="taco/:name" handler={Taco}/>
</Route>
);
Router.run(routes, function (Handler) {
React.render(<Handler/>, document.getElementById('example'));
});