2019-07-24 17:10:44 +00:00
|
|
|
import React from 'react';
|
|
|
|
import './App.css';
|
|
|
|
import { Client } from 'rpc-websockets'
|
|
|
|
import NodeList from "./NodeList";
|
|
|
|
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
|
|
|
const client = new Client('ws://127.0.0.1:2222/rpc/v0')
|
|
|
|
client.on('open', () => {
|
|
|
|
this.setState(() => ({client: client}))
|
|
|
|
})
|
|
|
|
|
2019-07-30 23:21:57 +00:00
|
|
|
this.state = {
|
|
|
|
windows: {},
|
|
|
|
nextWindow: 0,
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mountWindow = this.mountWindow.bind(this)
|
|
|
|
}
|
|
|
|
|
|
|
|
mountWindow(cb) {
|
|
|
|
const id = this.state.nextWindow
|
|
|
|
this.setState({nextWindow: id + 1})
|
|
|
|
|
|
|
|
const window = cb(() => {
|
|
|
|
this.setState(prev => ({windows: {...prev.windows, [id]: undefined}}))
|
|
|
|
})
|
|
|
|
|
|
|
|
this.setState(prev => ({windows: {...prev.windows, [id]: window}}))
|
2019-07-24 17:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
if (this.state.client === undefined) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
Connecting to RPC
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="App">
|
2019-07-30 23:21:57 +00:00
|
|
|
<NodeList client={this.state.client} mountWindow={this.mountWindow}/>
|
|
|
|
<div>
|
|
|
|
{Object.keys(this.state.windows).map((w, i) => <div key={i}>{this.state.windows[w]}</div>)}
|
|
|
|
</div>
|
2019-07-24 17:10:44 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App
|