-
Notifications
You must be signed in to change notification settings - Fork 4
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
Make a hypothetical package:html #2
base: master
Are you sure you want to change the base?
Conversation
Hoping this'll maybe kick start a discussion. I could see how the JS stuff could be generated through something like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments about what happens with dart2js. If you don't minify and modify the call sites for the JS code to hit the <method>$<argCount>
variants then things actually work as expected.
I know there's a package:meta/dart2js.dart
perhaps something like an @extern
might be useful here to signal to the compiler that it shouldn't mangle.
customElements.define(name, class extends CustomElement { | ||
constructor() { | ||
super(); | ||
construct(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First problem this hits in dart2js is that its not a function at this point. If you change it locally to construct.call$1
it gets further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which call isn't a function yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I added the construct.call$1
in there.
|
||
void connected() {} | ||
void disconnected() {} | ||
void attributeChanged(String attribute, String oldValue, String newValue) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These methods will get removed by dart2js
as they are really only referenced by the JS. The other problem is they get mangled as well so the JS code can't call them directly.
Update: This won't work until the above issue is resolved. Constructors in JS and in Dart both are not functions after compiled with dart2js. Thanks for including me anyway. Okay I've got a rough plan of how this might work. One of the goals of this approach is to support random JS custom elements that may not be willing to support dart explicitly.
I've done some usability tests for js_interop that still need to check parent/child relationships before submitting a PR. I also started the package:js version of HTMLElement and it's parent classes before realizing a minimal test should be done first. I should have this done in a week or two if tests validate my assumptions. |
@jifalops it might save you some work later to think about how this can be done in general through I'm to privy to the dart team's goals but a lot of the worklet specs make things a bit more interesting for the interop case. I think it would be interesting if framework authors could roll their own JS interop in the browser. Either way I'm really excited to see what you come up with. |
This is super cool by the way, thanks for putting this together! Yeah, I'm working on improvements to JS interop, so we can do an interop-based package:html. (Also trying to figure out the migration story.) I'll definitely keep custom elements in mind. |
@jmesserly I was actually experimenting further with a Not sure if that's clear enough but you can try and wrap Event and you'll hit it really quick. Only other thing I found had to do with Happy to add more examples for you if that would be of use. You and @jifalops are the experts with the interop so I'd defer to you guys on all that. |
Yeah, one of my goals is to make the Interceptor system unnecessary for the DOM. |
@donny-dont Some takeaways so far:
I think I've finally laid any hopes of non-closure function interop to rest for now. As @jmesserly said on StackOverflow regarding this, it's best to just use ... I started on this path because I have been developing ways of creating Mobile+Web applications. Sharing a theme with AngularDart was kind of tough and I thought MDC web offered a way to use rather plain HTML/JS and achieve a similar result. Anyway, I found this job post for what sounds like a position on the Dart team doing exactly that, developing mobile+web solutions. Maybe it involves helping sort out this |
With regard to best practices when 'wrapping' JavaScript using Also the wrapper class can declare itself to implement its underlying This might be unclear, there's an example of the second paragraph here |
Do you mind me asking why you're avoiding abstract classes? |
It's really just to be transparent and denote that the actual javascript version can be instantiated. Abstract lets you declare a property as I'm not sure that it really makes a difference though, since all |
@jmesserly if there's a bug you create for |
@jmesserly happy new year! Just pinging you to see if there's anything in the works since I hadn't heard anything with my last message. |
Happy new year to you to! Yeah, there's a lot happening, I'll be updating this issue: dart-lang/sdk#35084 |
@jmesserly so I managed to get Custom Elements working with DDC and dart2js. |
So I kept tinkering with things and was starting to think what a pure
package:js
version of adart:html
lib might look like.Talked with @jakemac53 while putting it together since he worked on polymer.dart. In there the dart object was attached to the js object. So this takes a similar approach.
Since not everything is wrapped it doesn't change color like the previous iteration. You can however play with the element by just entering the console. If you do that you can setAttribute on name and it'll change as expected.
@jmesserly @jifalops it would be interesting to hear your thoughts on it. Its probably closer to what would need to happen to have a
package:html
for dart web apps.Some other observations
dart:html
was not included at all.dart:html
is a thing.