8000 Merge pull request #43 from anaconda/quickfix/new_id_broke_repl · testnest/pyscript@c065c32 · GitHub
[go: up one dir, main page]

Skip to content

Commit c065c32

Browse files
authored
Merge pull request pyscript#43 from anaconda/quickfix/new_id_broke_repl
move check id out of constructor
2 parents ea63e36 + 45d68f5 commit c065c32

File tree

3 files changed

+30
-23
lines changed

3 files changed

+30
-23
lines changed

pyscriptjs/src/components/base.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ export class BaseEvalElement extends HTMLElement {
4545
this.shadow = this.attachShadow({ mode: 'open'});
4646
this.wrapper = document.createElement('slot');
4747
this.shadow.appendChild(this.wrapper);
48-
if (!this.id)
49-
this.id = this.constructor.name+"-"+guidGenerator()
50-
}
48+
}
5149

5250
addToOutput(s: string) {
5351
this.outputElement.innerHTML += "<div>"+s+"</div>";
@@ -58,6 +56,11 @@ export class BaseEvalElement extends HTMLElement {
5856

5957
}
6058

59+
checkId(){
60+
if (!this.id)
61+
this.id = this.constructor.name+"-"+guidGenerator();
62+
}
63+
6164
getSourceFromElement(): string{
6265
return "";
6366
}
@@ -165,6 +168,8 @@ export class BaseEvalElement extends HTMLElement {
165168
} // end eval
166169
}
167170

171+
172+
168173
function createWidget(name: string, code: string, klass: string){
169174

170175
class CustomWidget extends HTMLElement{

pyscriptjs/src/components/pyrepl.ts

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,27 @@ export class PyRepl extends BaseEvalElement {
5959

6060

6161
connectedCallback() {
62-
this.code = this.innerHTML;
63-
this.innerHTML = '';
64-
65-
let extensions = [
66-
basicSetup,
67-
languageConf.of(python()),
68-
keymap.of([
69-
...defaultKeymap,
70-
{ key: "Ctrl-Enter", run: createCmdHandler(this) },
71-
{ key: "Shift-Enter", run: createCmdHandler(this) }
72-
]),
73-
74-
// Event listener function that is called every time an user types something on this editor
75-
// EditorView.updateListener.of((v:ViewUpdate) => {
76-
// if (v.docChanged) {
77-
// console.log(v.changes);
78-
79-
// }
80-
// })
81-
];
62+
this.checkId()
63+
this.code = this.innerHTML;
64+
this.innerHTML = '';
65+
66+
let extensions = [
67+
basicSetup,
68+
languageConf.of(python()),
69+
keymap.of([
70+
...defaultKeymap,
71+
{ key: "Ctrl-Enter", run: createCmdHandler(this) },
72+
{ key: "Shift-Enter", run: createCmdHandler(this) }
73+
]),
74+
75+
// Event listener function that is called every time an user types something on this editor
76+
// EditorView.updateListener.of((v:ViewUpdate) => {
77+
// if (v.docChanged) {
78+
// console.log(v.changes);
79+
80+
// }
81+
// })
82+
];
8283

8384
if (!this.hasAttribute('theme')) {
8485
this.theme = this.getAttribute('theme');

pyscriptjs/src/components/pyscript.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export class PyScript extends BaseEvalElement {
9898
}
9999

100100
connectedCallback() {
101+
this.checkId()
101102
this.code = this.innerHTML;
102103
this.innerHTML = '';
103104
let startState = EditorState.create({

0 commit comments

Comments
 (0)
0