Waiting js till pyscript loads up #1587
-
Hi, I am working on a project and I am currently stuck on the issue where javascript runs before Pyscript and causing some issues where I can access a python object causes it hasn't been declared by Pyscript. I looked into the documentation and it has been stated there that this issue can occur but to solve it they are just delaying the program until a button is clicked which is not ideal for my case. Link to doc:(https://docs.pyscript.net/latest/guides/passing-objects.html#javascript-to-pyscript:~:text=Since%20PyScript%20tags,would%20be%20valid.) So I would like to know what other ways I can use instead of a button to run my javascript after Pyscript has loaded up |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
there are events dispatched via pyscript but also a globally shared registry that should guarantee when customElements.whenDefined('py-script').then(() => {
// here py-script is surely ready to go
});
// alternative: in a module, via top-level await
await customElements.whenDefined('py-script'); |
Beta Was this translation helpful? Give feedback.
OK, this is tested and working as expected. It simply tries until the interpreter is ready, starting to try when the py-script element is defined and never before.
This is not super elegant but it gets the job done in a non-blocking, prettty fast, way.
(IMHO) We should have a better way to do this and we will have such better way in next.