mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-23 12:12:59 -05:00
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:
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user