Auto-generate element ID to ensure output is rendered

This commit is contained in:
Philipp Rudiger
2022-04-21 20:40:24 +02:00
parent dc9e7e60cb
commit 190ae39690
2 changed files with 10 additions and 3 deletions

View File

@@ -27,6 +27,12 @@ type PyodideInterface = {
registerJsModule(name: string, module: object): void
}
export function guidGenerator(): string {
var S4 = function(): string {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
export class BaseEvalElement extends HTMLElement {
shadow: ShadowRoot;
@@ -46,6 +52,8 @@ export class BaseEvalElement extends HTMLElement {
this.shadow = this.attachShadow({ mode: 'open'});
this.wrapper = document.createElement('slot');
this.shadow.appendChild(this.wrapper);
if (!this.id)
this.id = this.constructor.name+"-"+guidGenerator()
}
addToOutput(s: string) {