-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.js
70 lines (57 loc) · 1.41 KB
/
application.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
import React from 'react';
import ReactDOM from 'react-dom';
import api from './api';
class LowerLevel extends React.Component {
onClick() {
api.update_x(this.props.x_id, Math.ceil(Math.random()*100));
}
render() {
return(
<div>
<p
style={{background:'#fafafa', padding:'10px', margin:'2px'}}
onMouseDown={this.onClick.bind(this)}>
value={this.props.x} (id={this.props.x_id})
</p>
</div>
);
}
}
class MidLevel extends React.Component {
render() {
const lower_levels = this.props.x_list.map(function(x){
return (<LowerLevel x_id={x['id']} x={x['x']} key={x['id']}/>)
});
return(
<div>
{lower_levels}
</div>
);
}
}
class TopLevel extends React.Component {
constructor(props){
super(props);
this.state = {
mid1: [],
mid2: [],
};
api.on_update(this.on_x_updated.bind(this));
}
run_queries() {
api.search_range(0, 50, (results) => {this.setState({mid1: results})});
api.search_range(50, 100, (results) => {this.setState({mid2: results})});
}
componentWillMount() { this.run_queries(); }
on_x_updated() { this.run_queries(); }
render() {
return(
<div>
<MidLevel x_list={this.state.mid1}/>
<hr/>
<MidLevel x_list={this.state.mid2}/>
</div>
);
}
}
ReactDOM.render(<TopLevel/>, document.getElementById('content'));