Update WASM example crate/app

This commit is contained in:
coolreader18 committed 2019-02-26 23:48:23 -06:00
1 parent 1d193e7fc7
commit 179304bc93
2 files changed
+14 -14

No files matched your search

+4 -9
View File
@@ -1,11 +1,6 @@
import * as py from 'rustpython_wasm';
import * as rp from 'rustpython_wasm';
import pyCode from 'raw-loader!./main.py';
fetch('https://github-trending-api.now.sh/repositories')
.then(r => r.json())
.then(repos => {
const result = py.pyEval(pyCode, {
vars: { repos }
});
alert(result);
});
const vm = rp.vmStore.get('main');
vm.exec(pyCode);
+10 -5
View File
@@ -1,8 +1,13 @@
repos = js_vars['repos']
from browser import fetch
star_sum = 0
def fetch_handler(repos):
star_sum = 0
for repo in repos:
star_sum += repo['stars']
print(f'Average github trending star count: {star_sum / len(repos)}')
for repo in repos:
star_sum += repo['stars']
return 'Average github trending star count: ' + str(star_sum / len(repos))
fetch(
'https://github-trending-api.now.sh/repositories',
response_format='json',
).then(fetch_handler)