mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
committed by
GitHub
parent
e7aed7fcf0
commit
ecc40315b3
@@ -11,6 +11,9 @@ import { InterpreterClient } from '../interpreter_client';
|
|||||||
|
|
||||||
const logger = getLogger('py-script');
|
const logger = getLogger('py-script');
|
||||||
|
|
||||||
|
// used to flag already initialized nodes
|
||||||
|
const knownPyScriptTags: WeakSet<HTMLElement> = new WeakSet();
|
||||||
|
|
||||||
export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp) {
|
export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp) {
|
||||||
/**
|
/**
|
||||||
* A common <py-script> VS <script type="py"> initializator.
|
* A common <py-script> VS <script type="py"> initializator.
|
||||||
@@ -64,6 +67,10 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp)
|
|||||||
_fetchSourceFallback = () => htmlDecode(this.srcCode);
|
_fetchSourceFallback = () => htmlDecode(this.srcCode);
|
||||||
|
|
||||||
async connectedCallback() {
|
async connectedCallback() {
|
||||||
|
// prevent multiple initialization of the same node if re-appended
|
||||||
|
if (knownPyScriptTags.has(this)) return;
|
||||||
|
knownPyScriptTags.add(this);
|
||||||
|
|
||||||
// Save innerHTML information in srcCode so we can access it later
|
// Save innerHTML information in srcCode so we can access it later
|
||||||
// once we clean innerHTML (which is required since we don't want
|
// once we clean innerHTML (which is required since we don't want
|
||||||
// source code to be rendered on the screen)
|
// source code to be rendered on the screen)
|
||||||
@@ -88,6 +95,10 @@ export function make_PyScript(interpreter: InterpreterClient, app: PyScriptApp)
|
|||||||
|
|
||||||
// bootstrap with the same connectedCallback logic any <script>
|
// bootstrap with the same connectedCallback logic any <script>
|
||||||
const bootstrap = (script: PyScriptElement) => {
|
const bootstrap = (script: PyScriptElement) => {
|
||||||
|
// prevent multiple initialization of the same node if re-appended
|
||||||
|
if (knownPyScriptTags.has(script)) return;
|
||||||
|
knownPyScriptTags.add(script);
|
||||||
|
|
||||||
const pyScriptTag = document.createElement('py-script-tag') as PyScript;
|
const pyScriptTag = document.createElement('py-script-tag') as PyScript;
|
||||||
|
|
||||||
// move attributes to the live resulting pyScriptTag reference
|
// move attributes to the live resulting pyScriptTag reference
|
||||||
|
|||||||
Reference in New Issue
Block a user