fix linting and types related issues (#731)

This commit is contained in:
Madhur Tandon
2022-08-27 02:18:01 +05:30
committed by GitHub
parent db806a5df9
commit 531ee928b0
3 changed files with 17 additions and 12 deletions

View File

@@ -1,8 +1,7 @@
import * as jsyaml from 'js-yaml';
import { BaseEvalElement } from './base';
import { appConfig } from '../stores';
import type { AppConfig } from '../runtime';
import { Runtime } from '../runtime';
import type { AppConfig, Runtime } from '../runtime';
import { PyodideRuntime, DEFAULT_RUNTIME_CONFIG } from '../pyodide';
/**
@@ -59,12 +58,12 @@ export class PyConfig extends BaseEvalElement {
loadRuntimes() {
console.log('Initializing runtimes...');
for (let runtime of this.values.runtimes) {
runtime = new PyodideRuntime(runtime.src, runtime.name, runtime.lang);
for (const runtime of this.values.runtimes) {
const runtimeObj: 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.src = runtimeObj.src; // set its src to the provided URL
script.addEventListener('load', () => {
void runtime.initialize();
void runtimeObj.initialize();
});
document.head.appendChild(script);
}

View File

@@ -1,4 +1,4 @@
import { Runtime } from './runtime';
import { Runtime, RuntimeConfig } from './runtime';
import { getLastPath, inJest } from './utils';
import type { PyodideInterface } from 'pyodide';
import { loadPyodide } from 'pyodide';
@@ -6,7 +6,7 @@ import { loadPyodide } from 'pyodide';
// @ts-ignore
import pyscript from './python/pyscript.py';
export const DEFAULT_RUNTIME_CONFIG = {
export const DEFAULT_RUNTIME_CONFIG: RuntimeConfig = {
src: 'https://cdn.jsdelivr.net/pyodide/v0.21.1/full/pyodide.js',
name: 'pyodide-default',
lang: 'python'
@@ -20,9 +20,9 @@ export class PyodideRuntime extends Runtime {
globals: any;
constructor(
src = 'https://cdn.jsdelivr.net/pyodide/v0.21.1/full/pyodide.js',
name = 'pyodide-default',
lang = 'python',
src = DEFAULT_RUNTIME_CONFIG.src,
name = DEFAULT_RUNTIME_CONFIG.name,
lang = DEFAULT_RUNTIME_CONFIG.lang,
) {
super();
this.src = src;

View File

@@ -14,11 +14,17 @@ import type { PyScript } from './components/pyscript';
export type RuntimeInterpreter = PyodideInterface | null;
export type RuntimeConfig = {
src: string;
name?: string;
lang?: string;
};
export type AppConfig = {
autoclose_loader: boolean;
name?: string;
version?: string;
runtimes?: Array<Runtime>;
runtimes?: Array<RuntimeConfig>;
};
let loader: PyLoader | undefined;