schultek / jaspr

Modern web framework for building websites in Dart. Supports SPAs, SSR and SSG.
https://jasprpad.schultek.de
MIT License
1.07k stars 65 forks source link

feat: use raw javascript in jaspr #140

Closed hamidjalili59 closed 9 months ago

hamidjalili59 commented 9 months ago

Imagine using an tag to implement a button, but in addition to using Dart code inside this tag, you want to use JavaScript code in the event of this button. This can be achieved by using a method like Styles.raw(). for example: JasprJS.raw(() { console.log("in Jaspr"); }).

For some libraries and features not found in Dart, you can leverage this feature.

schultek commented 9 months ago

This is not something I plan to implement for a couple of reasons:

It would either require modifying the js compiler, or use something like the 'eval' function in js, which is neither efficient nor secure. The recommended way here is to use js interop as described here: https://dart.dev/web/js-interop

And if you still want something like you showed, you can wrap the 'eval()' function yourself in just a couple of lines.