-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
45 lines (39 loc) · 1.17 KB
/
script.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
// globals ace
const editorSource = ace.edit("editor-source");
editorSource.setTheme("ace/theme/tomorrow_night");
editorSource.session.setMode("ace/mode/python");
const editorTransformed = ace.edit("editor-transformed");
editorTransformed.setReadOnly(true);
editorTransformed.setTheme("ace/theme/tomorrow_night");
editorTransformed.session.setMode("ace/mode/python");
async function fetchTransformedSource(source) {
const response = await fetch("/api/transform", {
method: "POST",
body: JSON.stringify({ source })
});
const body = await response.json();
return body.source;
}
let calls = 0;
async function onEditorUpdated() {
const call = ++calls;
const transformed = await fetchTransformedSource(editorSource.getValue());
if (call === calls) {
editorTransformed.setValue(transformed);
editorSource.clearSelection();
editorTransformed.clearSelection();
}
}
editorSource.setValue(`"""
A simple coroutine.
"""
from tornado import gen
@gen.coroutine
def call_api():
response = yield fetch()
if response.status != 200:
raise BadStatusError()
raise gen.Return(response.data)
`);
onEditorUpdated();
editorSource.on("change", onEditorUpdated);