8000 Patch js.document out of the box by WebReflection · Pull Request #1880 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

Patch js.document out of the box #1880

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Patch js.document out of the box
  • Loading branch information
WebReflection committed Dec 1, 2023
commit d4ab81614853836fb284f7bbac2afa277858f357
3 changes: 3 additions & 0 deletions pyscript.core/src/stdlib/pyscript/magic_js.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import js as globalThis
from polyscript import js_modules

from pyscript.util import NotSupported

RUNNING_IN_WORKER = not hasattr(globalThis, "document")

if RUNNING_IN_WORKER:
import js
import polyscript

PyWorker = NotSupported(
Expand All @@ -13,6 +15,7 @@
)
window = polyscript.xworker.window
document = window.document
js.document = document
sync = polyscript.xworker.sync

# in workers the display does not have a default ID
Expand Down
5 changes: 5 additions & 0 deletions pyscript.core/test/worker.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import a

from pyscript import display, sync

display("Hello World", target="test", append=True)

print("sleeping")
sync.sleep(1)
print("awake")

import js

js.document.body.append("document patch ")
0