Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update App.tsx #291

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import './App.css';
*/
interface IState {
data: ServerRespond[],
showGeaph: boolean,
}

/**
Expand All @@ -22,25 +23,36 @@ class App extends Component<{}, IState> {
// data saves the server responds.
// We use this state to parse data down to the child element (Graph) as element property
data: [],
showGraph: false,
};
}

/**
* Render Graph react component with state.data parse as property data
*/
renderGraph() {
if (this.state.showGraph)
return (<Graph data={this.state.data}/>)
}
}

/**
* Get new data from server and update the state with the new data
*/
getDataFromServer() {
DataStreamer.getData((serverResponds: ServerRespond[]) => {
// Update the state by creating a new array of data that consists of
// Previous data in the state and the new data from server
this.setState({ data: [...this.state.data, ...serverResponds] });
});
let x =0;
const interval =setInterval(() =>{
DataStreamer.getData((serverResoand:ServerRespond[]) => {
this.setState({
data: serverResoand,
showGraph: true,
});
});
x++;
if(x >1000){
clearInterval(interval);
}
},100);
}

/**
Expand Down