From c6b5ce7f55e1eab33484983d9cde2a598b4801ae Mon Sep 17 00:00:00 2001 From: Andrea Giammarchi Date: Thu, 6 Jul 2023 17:56:06 +0200 Subject: [PATCH] [next] Drop web like events (#1578) * Use registerJSModule when available (#1573) * Updated version to publish latest --- pyscript.core/docs/README.md | 33 ++++--------------- pyscript.core/esm/interpreter/_python.js | 2 ++ pyscript.core/esm/interpreter/micropython.js | 2 ++ pyscript.core/esm/interpreter/pyodide.js | 2 ++ .../esm/interpreter/ruby-wasm-wasi.js | 12 +++++++ pyscript.core/esm/interpreter/wasmoon.js | 1 + pyscript.core/esm/listeners.js | 8 ++--- pyscript.core/package.json | 4 +-- pyscript.core/pyscript.js | 2 +- pyscript.core/test/plugins/index.html | 4 +-- pyscript.core/test/py-events.html | 8 ++--- pyscript.core/test/ruby.html | 4 +-- pyscript.core/test/wasmoon.html | 2 +- pyscript.core/test/worker/input.html | 2 +- 14 files changed, 40 insertions(+), 46 deletions(-) diff --git a/pyscript.core/docs/README.md b/pyscript.core/docs/README.md index 20ac7a7a..aeece740 100644 --- a/pyscript.core/docs/README.md +++ b/pyscript.core/docs/README.md @@ -246,40 +246,19 @@ Please read the [XWorker](#xworker) dedicated section to know more. ## How Events Work -Inspired by the current [HTML Standard](https://html.spec.whatwg.org/multipage/webappapis.html#event-handlers): - -> the event handler is exposed through a name, which is a string that always starts with "_on_" and is followed by the name of the event for which the handler is intended. - -We took a similar approach, replacing that `on` prefix with whatever *interpreter* or *custom type* is available on the page, plus a *dash* `-` to avoid clashing with standards: +The event should contain the *interpreter* or *custom type* prefix, followed by the *event* type it'd like to handle. ```html - ``` -If this example felt a bit verbose, be ensured custom types would work the same: - -```html - - -``` - -What is important to understand about *events* in PyScript is that the text within the attribute is executed just like any other inline or external content is, through the very same *interpreter*, with the notably extra feature that the `event` reference is made temporarily available as *global* by *core*. - -This really reflects how otherwise native Web inline events handlers work and we think it's a great feature to support ... *but*: - - * if your script runs *asynchronously* the `event` might be gone on the main / UI thread and by that time any of its `event.stopPropagation()` or `event.preventDefault()` goodness will be problematic, as too late to be executed - * if your *interpreter* is *experimental*, or incapable of running *synchronous* events, the `event` reference might be less useful - -ℹ️ - Please note that if your code runs via *XWorker*, hence in a different thread, there are different caveats and constraints to consider. Please read the [XWorker](#xworker) dedicated section to know more. +Differently from *Web* inline events, there's no code evaluation at all within the attribute: it's just a globally available name that will receive the current event and nothing else. #### The type-env attribute @@ -299,7 +278,7 @@ Just as the `env` attribute on a ` - + def test_click(event): print(event.type) diff --git a/pyscript.core/test/py-events.html b/pyscript.core/test/py-events.html index 89474441..9a3afacc 100644 --- a/pyscript.core/test/py-events.html +++ b/pyscript.core/test/py-events.html @@ -16,8 +16,8 @@ print(sys.version) @@ -29,8 +29,8 @@ print(sys.version) diff --git a/pyscript.core/test/ruby.html b/pyscript.core/test/ruby.html index 14a6bdcc..7d6635e6 100644 --- a/pyscript.core/test/ruby.html +++ b/pyscript.core/test/ruby.html @@ -15,7 +15,7 @@ } } - + - diff --git a/pyscript.core/test/wasmoon.html b/pyscript.core/test/wasmoon.html index a2ea615d..f828a387 100644 --- a/pyscript.core/test/wasmoon.html +++ b/pyscript.core/test/wasmoon.html @@ -33,6 +33,6 @@ print(read_file('/a.py')) end - + diff --git a/pyscript.core/test/worker/input.html b/pyscript.core/test/worker/input.html index 9c022474..08ce0a18 100644 --- a/pyscript.core/test/worker/input.html +++ b/pyscript.core/test/worker/input.html @@ -45,7 +45,7 @@