Skip to content
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

More beginner-friendly examples for a new JS interop, not just breadcrumbs and inconsistent boilerplates, please ! [FEATURE REQUEST] #5674

Open
projektorius96 opened this issue Mar 28, 2024 · 5 comments
Assignees
Labels
a.tut.tutorial Relates to the Tutorial section of dart.dev dev.interop Relates to use of native code as part of your Dart app e3-weeks Complete in < 4 weeks of normal, not dedicated, work p3-low Valid but not urgent concern. Resolve when possible. Encourage upvote to surface. target.web Target apps on the web platform

Comments

@projektorius96
Copy link

Coming from JavaScript world, the docs for JS Interop, in my sheer opinion are useless, we need more beginner friendly step by step basis examples ! Take as an example usage section, the usage section focuses on Dart, but does not even show a pseudo idiomatic code which explain how it binds the stuff with JavaScript, at least syntax-wise.

I'd love to see the approach where everything about JS interop is explained step by step basis. I am currently actively building HTML Canvas based PWA similar to online Desmos but offline-first, and because the codebase grows exponentially I decided to ship to Dart rather to controversial TypeScript. Yes, my goal is to bind it with Dart, so package:web would do a job, but dart:js_interop examples around which package:web is built, like I said before, bunch of inconsistent boilerplates that cannot be easily grasped, to be honest a guy who can write Golang code, I could understand the C interop better than all is written in the JS Interop section on Dart docs. I don't know about other people experience towards this question, but that's me. The only I have recently read on Discord channel, that the guy chosen TypeScript over Dart, because of lack of documentation. Keeping in mind all happens under Google, it's really sad, just like Steve Ballmer said "Developers Developers Developers", I say "Documentation Documentation Documentation" ! Hopefully the administrators will take this features request positively, cheers !

@parlough
Copy link
Member

parlough commented Mar 28, 2024

Thanks for the issue and feedback!

I definitely agree that we need more step-by-step documentation here (for JS and other forms of interop). This form of JS interop was just released this past month and was a large migration from previous styles, so the initial documentation focused on migrating from the old system. I hope we can find time soon to introduce more documentation, including tutorial like docs, but we are also happy to accept pull requests in the mean time!

Is there a specific topic or example that you think would be helpful to your learning experience? Any insight here would help guide development of future learning materials.

If you notice other specific issues or areas of improvement, please file more issues at https://github.com/dart-lang/site-www/issues.

If you have questions using JS interop, consider asking on the Dart Discord and if you find any issues or notice any developer experience issues, open an issue on the Dart SDK repository.

Thanks again and I'm sorry the new JS-interop documentation didn't have what you were looking for yet.

@srawlins
Copy link
Member

@parlough should I transfer this to https://github.com/dart-lang/site-www/issues?

@parlough
Copy link
Member

If you are able to, yes please :)

@srawlins
Copy link
Member

srawlins commented Mar 28, 2024

Oh I forgot, there's... red tape or something. I cannot. :(

I figured it out. Transferred.

@srawlins srawlins transferred this issue from dart-lang/dartdoc Mar 29, 2024
@parlough parlough added p3-low Valid but not urgent concern. Resolve when possible. Encourage upvote to surface. a.tut.tutorial Relates to the Tutorial section of dart.dev target.web Target apps on the web platform dev.interop Relates to use of native code as part of your Dart app e3-weeks Complete in < 4 weeks of normal, not dedicated, work labels Mar 29, 2024
parlough added a commit that referenced this issue Apr 9, 2024
I have discovered that the dart web [get started](https://dart.dev/web/get-started) code example does not match
the new dart:web interface. Therefore I have updated the documentation.

Fixes: There is no specific issue, but it certainly helps #5674 and
#5525

---------

Co-authored-by: Parker Lougheed <parlough@gmail.com>
@jarrodcolburn
Copy link
Contributor

jarrodcolburn commented Apr 23, 2024

Since the dart:js_interop library says "WARNING: This library is still a work in progress" I kinda expect the team to be more focused on developing the features, than documenting them. So although, I agree it's lacking, I kinda think it's expected atm.

That said, (maybe I'm missing it) but the thing I would appreciate seeing that I don't currently, and would be a step in this what I believe OP thinks is the right direction is...

How to use/load .js files to use the dart bindings?

And, What should the project directory/file structure look like?

Take for instance the Example on Usage page for Top-level Interop members Which provides a js and dart snippet.

globalThis.name = 'global';
globalThis.isNameEmpty = function() {
  return globalThis.name.length == 0;
}
@JS()
external String get name;

@JS()
external set name(String value);

@JS()
external bool isNameEmpty();

Unfortunately, the js and dart above it doesn't really tell you how to load the js. Like is the js supposed to be in a .js file? If so where?

I know from trying it in a Simple Dart Web app that we can save the js to something like myscript.js and edit the index.html to include...

<script src="myscript.js" >

...to load it. But I don't really see that documented, and I'm not even sure if editing the html is the recommended way of loading js. I actually hope not.

I see importModule() method exists, but I don't see an usage or example on how to use it. Is that what I should be using? If so, what's the setup for the modules, and where do they belong in the project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a.tut.tutorial Relates to the Tutorial section of dart.dev dev.interop Relates to use of native code as part of your Dart app e3-weeks Complete in < 4 weeks of normal, not dedicated, work p3-low Valid but not urgent concern. Resolve when possible. Encourage upvote to surface. target.web Target apps on the web platform
Projects
None yet
Development

No branches or pull requests

5 participants