3 ms·
WebComponents are an amazing replacement for jQuery, get the best of frontend Component based development without the bloat and the JS toolchain! Vanilla JS is
by 1337shadow 5y ago
WebComponents are an amazing replacement for jQuery, get the best of frontend Component based development without the bloat and the JS toolchain! Vanilla JS is great with WebComponents. We even write them in python with Ryzom's transpiler:
```
class DeleteButton(Component):
tag = 'delete-button'
class HTMLElement:
def connectedCallback(self):
this.addEventListener('click', this.delete.bind(this))
async def delete(self, event):
csrf = document.querySelector('[name="csrfmiddlewaretoken"]')
await fetch(this.attributes['delete-url'].value, {
method: 'delete',
headers: {'X-CSRFTOKEN': csrf.value},
redirect: 'manual',
}).then(lambda response: print(response))
```
Speaking of which, Rails ViewComponent looks a lot like Python Ryzom, except the later optionnaly supports data-binding over websockets.
But writing JS in Python is extremely satisfying if you already like writing Python more than you like writing JS ;)
- josephorjoe 5y agoas someone who regularly works w python and javascript and misses being able to just write some simple html, this code snippet is going to give me nightmares... i assume any linter for this code will one day become sentient.
- deleted 5y ago[deleted]