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

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

parent c246e9ac
...@@ -69,16 +69,21 @@ class App extends React.Component { ...@@ -69,16 +69,21 @@ class App extends React.Component {
test = ""; test = "";
} }
processWaccCode = (code) => { processWaccCode = async (code) => {
let rsp = sendWaccCode(code) let rsp = await sendWaccCode(code);
console.log(rsp) let graph = this.state.graphData;
let graph = astMetaToGraphData(rsp.astMeta) 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() { render() {
...@@ -141,11 +146,11 @@ class App extends React.Component { ...@@ -141,11 +146,11 @@ class App extends React.Component {
<GridItem xs={12} sm={12} md={6}> <GridItem xs={12} sm={12} md={6}>
<Card> <Card>
<CardBody> <CardBody>
<div style={{height: '50em'}}> <div style={{height: '50em'}}>
<Tree <Tree
data={this.state.graphData} data={this.state.graphData}
orientation="vertical"/> orientation="vertical"/>
</div> </div>
</CardBody> </CardBody>
</Card> </Card>
</GridItem> </GridItem>
......
...@@ -17,16 +17,19 @@ export function astMetaToGraphData(astMeta) { ...@@ -17,16 +17,19 @@ export function astMetaToGraphData(astMeta) {
} }
export async function sendWaccCode(code) { export async function sendWaccCode(code) {
let ADDR = SERVER_ADDR + SERVER_ENDPOINT let ADDR = SERVER_ADDR + SERVER_ENDPOINT;
// console.log(`Sending ${code} to ${ADDR}`) var data = {isError: true};
await axios.post(ADDR, {contents: code}, {headers:{'Content-Type': 'application/json'}}) await axios.post(ADDR, {contents: code}, {headers:{'Content-Type': 'application/json'}})
.then(res => { .then(res => {
console.log(res.data) data = res.data
return res.data
// console.log(res)
})
.catch(reason => {
// console.log(reason)
return
}) })
.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