make runtime an object of Runtime class when it is just an object (#729)

* make runtime an object of Runtime class when it is just an object

* fix constructor

* remove explicit string type

* define default values out of pyodide runtime and use default config instead of initializing a DEFAULT_RUNTIME instance

Co-authored-by: Fabio Pliger <fabio.pliger@gmail.com>
This commit is contained in:
Madhur Tandon
2022-08-27 01:49:03 +05:30
committed by GitHub
parent 9de154595a
commit db806a5df9
2 changed files with 31 additions and 15 deletions

View File

@@ -1,10 +1,9 @@
import * as jsyaml from 'js-yaml';
import { BaseEvalElement } from './base';
import { appConfig } from '../stores';
import type { Runtime, AppConfig } from '../runtime';
import { PyodideRuntime } from '../pyodide';
const DEFAULT_RUNTIME: Runtime = new PyodideRuntime();
import type { AppConfig } from '../runtime';
import { Runtime } from '../runtime';
import { PyodideRuntime, DEFAULT_RUNTIME_CONFIG } from '../pyodide';
/**
* Configures general metadata about the PyScript application such
@@ -34,15 +33,14 @@ export class PyConfig extends BaseEvalElement {
if (loadedValues === undefined) {
this.values = {
autoclose_loader: true,
runtimes: [DEFAULT_RUNTIME_CONFIG]
};
} else {
// eslint-disable-next-line
// @ts-ignore
this.values = loadedValues;
}
if (this.values.runtimes === undefined) {
this.values.runtimes = [DEFAULT_RUNTIME];
}
appConfig.set(this.values);
console.log('config set', this.values);
@@ -61,7 +59,8 @@ export class PyConfig extends BaseEvalElement {
loadRuntimes() {
console.log('Initializing runtimes...');
for (const runtime of this.values.runtimes) {
for (let runtime of this.values.runtimes) {
runtime = new PyodideRuntime(runtime.src, runtime.name, runtime.lang);
const script = document.createElement('script'); // create a script DOM node
script.src = runtime.src; // set its src to the provided URL
script.addEventListener('load', () => {