Commit 2cf4353f authored by Raghav Khanna's avatar Raghav Khanna

Use async and await function return. If nor error update state.

parent c246e9ac
......@@ -69,16 +69,21 @@ class App extends React.Component {
test = "";
}
processWaccCode = (code) => {
let rsp = sendWaccCode(code)
console.log(rsp)
let graph = astMetaToGraphData(rsp.astMeta)
processWaccCode = async (code) => {
let rsp = await sendWaccCode(code);
let graph = this.state.graphData;
if (typeof rsp.isError !== "undefined") {
} else {
graph = astMetaToGraphData(rsp.astMeta);
this.setState({
arm: {code: rsp.armCode},
js: {code: rsp.jsCode},
graphData: graph
})
}
this.setState({
arm: {code: rsp.armCode},
js: {code: rsp.jsCode},
graphData: graph
})
}
render() {
......@@ -141,11 +146,11 @@ class App extends React.Component {
<GridItem xs={12} sm={12} md={6}>
<Card>
<CardBody>
<div style={{height: '50em'}}>
<Tree
data={this.state.graphData}
orientation="vertical"/>
</div>
<div style={{height: '50em'}}>
<Tree
data={this.state.graphData}
orientation="vertical"/>
</div>
</CardBody>
</Card>
</GridItem>
......
......@@ -17,16 +17,19 @@ export function astMetaToGraphData(astMeta) {
}
export async function sendWaccCode(code) {
let ADDR = SERVER_ADDR + SERVER_ENDPOINT
// console.log(`Sending ${code} to ${ADDR}`)
let ADDR = SERVER_ADDR + SERVER_ENDPOINT;
var data = {isError: true};
await axios.post(ADDR, {contents: code}, {headers:{'Content-Type': 'application/json'}})
.then(res => {
console.log(res.data)
return res.data
// console.log(res)
})
.catch(reason => {
// console.log(reason)
return
data = res.data
})
.catch(error => {
if(typeof error.response.data.errors !== "undefined" ){
var errors = error.response.data.errors;
for (let entry of errors.keys()) {
console.log(errors[entry])
}
}
});
return data
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment