-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (59 loc) · 1.67 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
import React from 'react';
import { render } from 'react-dom';
import { Doodle3DManager } from './src/index.js';
class Box extends React.Component {
state = {
status: {}
};
componentWillMount() {
const { box } = this.props;
box.setAutoUpdate(true, 1000);
box.addEventListener('update', ({ state }) => {
this.setState({ status: state });
});
}
componentWillUnMount() {
const { box } = this.props;
box.setAutoUpdate(false);
}
render() {
return (
<div>
<p><b>name: {this.props.box.boxData.wifiboxid}</b></p>
<ul>
{Object.entries(this.state.status).map(([key, value]) => <li key={key}>{key}: {value}</li>)}
</ul>
</div>
);
};
}
class OverView extends React.Component {
state = {
boxes: []
};
componentWillMount() {
const doodle3DManager = new Doodle3DManager();
doodle3DManager.checkNonServerBoxes = false;
doodle3DManager.setAutoUpdate(true, 1000);
doodle3DManager.addEventListener('boxappeared', ({ box }) => {
this.setState({ boxes: [...this.state.boxes, <Box box={box} />] })
});
doodle3DManager.addEventListener('boxdisappeared', ({ box }) => {
this.setState({ boxes: this.state.boxes.filter(box => box.props.box.boxData.id !== box.boxData.id) })
});
this.setState({ doodle3DManager })
}
componentWillUnMount() {
const { doodle3DManager } = this.state;
if (doodle3DManager) doodle3DManager.setAutoUpdate(false);
}
render() {
const { boxes } = this.state;
return (
<div>
{boxes.map((box, i) => <span key={i}>{box}</span>)}
</div>
);
};
}
render(<OverView />, document.getElementById('app'));