8000 clean pyscript.ts · YComputer/pyscript@99c79ac · GitHub
[go: up one dir, main page]

Skip to content

Commit 99c79ac

Browse files
committed
clean pyscript.ts
1 parent ec38f9c commit 99c79ac

File tree

3 files changed

+3
-56
lines changed

3 files changed

+3
-56
lines changed

pyscriptjs/src/components/pyinputbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseEvalElement } from './base';
2-
import { addClasses, ltrim, htmlDecode } from '../utils';
2+
import { addClasses, htmlDecode } from '../utils';
33

44
export class PyInputBox extends BaseEvalElement {
55
shadow: ShadowRoot;

pyscriptjs/src/components/pyrepl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { keymap } from '@codemirror/view';
55
import { defaultKeymap } from '@codemirror/commands';
66
import { oneDarkTheme } from '@codemirror/theme-one-dark';
77

8-
import { componentDetailsNavOpen, currentComponentDetails, loadedEnvironments, mode, pyodideLoaded } from '../stores';
8+
import { componentDetailsNavOpen, loadedEnvironments, mode, pyodideLoaded } from '../stores';
99
import { addClasses } from '../utils';
1010
import { BaseEvalElement } from './base';
1111

pyscriptjs/src/components/pyscript.ts

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import { EditorState } from '@codemirror/basic-setup';
2-
import { python } from '@codemirror/lang-python';
3-
import { StateCommand } from '@codemirror/state';
4-
import { keymap } from '@codemirror/view';
5-
import { defaultKeymap } from '@codemirror/commands';
6-
import { oneDarkTheme } from '@codemirror/theme-one-dark';
7-
81
import {
92
addInitializer,
103
addPostInitializer,
114
addToScriptsQueue,
12-
componentDetailsNavOpen,
135
loadedEnvironments,
146
mode,
157
pyodideLoaded,
@@ -21,7 +13,6 @@ import { BaseEvalElement } from './base';
2113
let pyodideReadyPromise;
2214
let environments;
2315
let currentMode;
24-
let handlersCollected = false;
2516

2617
pyodideLoaded.subscribe(value => {
2718
pyodideReadyPromise = value;
@@ -30,11 +21,6 @@ loadedEnvironments.subscribe(value => {
3021
environments = value;
3122
});
3223

33-
let propertiesNavOpen;
34-
componentDetailsNavOpen.subscribe(value => {
35-
propertiesNavOpen = value;
36-
});
37-
3824
mode.subscribe(value => {
3925
currentMode = value;
4026
});
@@ -45,44 +31,6 @@ type PyodideInterface = {
4531
registerJsModule(name: string, module: object): void;
4632
};
4733

48-
// TODO: This should be used as base for generic scripts that need exectutoin
49-
// from PyScript to initializers, etc...
50-
class Script {
51-
source: string;
52-
state: string;
53-
output: string;
54-
55-
constructor(source: string, output: string) {
56-
this.output = output;
57-
this.source = source;
58-
this.state = 'waiting';
59-
}
60-
61-
async evaluate() {
62-
console.log('evaluate');
63-
const pyodide = await pyodideReadyPromise;
64-
// debugger
65-
try {
66-
// let source = this.editor.state.doc.toString();
67-
let output;
68-
if (this.source.includes('asyncio')) {
69-
output = await pyodide.runPythonAsync(this.source);
70-
} else {
71-
output = pyodide.runPython(this.source);
72-
}
73-
74-
if (this.output) {
75-
// this.editorOut.innerHTML = s;
76-
}
77-
// if (output !== undefined){
78-
// this.addToOutput(output);
79-
// }
80-
} catch (err) {
81-
console.log('OOOPS, this happened: ', err);
82-
// this.addToOutput(err);
83-
}
84-
}
85-
}
8634

8735
export class PyScript extends BaseEvalElement {
8836
constructor() {
@@ -207,7 +155,6 @@ async function initHandlers() {
207155
// // pyodide.runPython(handlerCode);
208156
// }
209157
}
210-
handlersCollected = true;
211158

212159
matches = document.querySelectorAll('[pys-onKeyDown]');
213160
for (const el of matches) {
@@ -222,7 +169,7 @@ async function mountElements() {
222169
console.log('Collecting nodes to be mounted into python namespace...');
223170
const pyodide = await pyodideReadyPromise;
224171
const matches: NodeListOf<HTMLElement> = document.querySelectorAll('[py-mount]');
225-
let output;
172+
226173
let source = '';
227174
for (const el of matches) {
228175
let mountName = el.getAttribute('py-mount');

0 commit comments

Comments
 (0)
0