[Py2js] Release blockers
To complete this issue, complete the following by removing as much code as possible at the same time:
-
Relpca Python print()
withconsole.log()
-
Replace Python CamelCase(
withnew CamelCase(
, -
Remove Python async
-
Translate getElementByUuid
withquerySelector('[ryzom-id="..."]')
-
Translate real await
instead of_await()
-
Don't use setattr, getattr: we're not trying to "compile python into js" but to "write js in python"! -
Remove py-builtins.js and all dependencies: start from a clean plate -
self
MUST NOT representthis
,this
will be implemented as a global for unit testing in python, it's not used in our functions yet -
$.def()
andautoexec
must go, users can explicitely that, this must not be done by default -
for x in range()
must be replaced by proper c-style forloop that doesn't call range
The js.renderer.JS
class is deprecated in favor of the @js
decorator, example rewritten ryzom_django_example.reactive.AjaxFormMixin:
# define two global functions with the `AjaxFormMixin__` prefix with @js.function
# define some code to be executed in the global scope with `@js`
class AjaxFormMixin(Script):
@js.function
def handle_response(response):
print(response.status)
@js.function
async def on_form_submit(event):
event.preventDefault()
form = event.target
data = {
'method': form.method,
'body': FormData(form)
}
form.reset()
await fetch(form.action, data).then(handle_response)
@js
def bind():
getElementByUuid(self.id).addEventListener('submit', on_form_submit)
Collect js.functions and @js in Script.render_js()!!
Open for discussion: the idea to define a bundle in python.
-
Implement # include
for bundling and defining getElementByUuid: Create a bundle.py with the following:
def getElementByUuid(uuid):
return querySelector(f'[ryzom-id="{uuid}"])
# bundle ryzom_django_example.reactive.AjaxFormMixin
py2js would be able to serve the above as pure js: it's a bundle that defines some globals, and imports the output of the transpiled rendering of the @js
code directly and @js.function
as part as a function() definition with the same name.
Edited by jpic ∞