-
Notifications
You must be signed in to change notification settings - Fork 171
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
Use Custom Elements v1 API #67
Conversation
Hey @josh! @notwaldorf asked me to comment on the I would stay far, far away from The basic problem is that V1 Custom Elements essentially must be written as ES6 classes. This is because it's not possible for an ES5-style class to extend an ES6 class because it can't invoke function RelativeTimeElement() {
var self = Reflect.construct(HTMLElement, [], RelativeTimeElement);
return self;
}
new RelativeTimeElement(); is creating 2 objects: one at the Since there is no way to perform a The native-shim is here, along with some details about why it's needed: https://github.com/webcomponents/custom-elements/blob/master/src/native-shim.js I hope that helps! |
Shipping an ES6 class seems like the right way to go for this repository. Though, "compile to ES5 only for those browsers that don't support ES6" seems to be glossed over. Has someone implemented a Babel transform that can correct extend Thanks! |
Babel compiled classes work as long as either the polyfill or the native-shim are loaded (this is because constructors in Babel output correctly return the value of the "super" call, the |
In terms of publishing, I'm proposing this package ship two source files.
|
@josh I have experimented with delivering ES2015 classes to browsers that support it, and in those that do, like Edge, the call to super() seemed to work well with shimmed HTMLElement constructors. But the browsers that don't support ES2015 class syntax also tend to not support Reflect.construct, and if the constructor has to be shimmed anyways, an ES5 class might as well just |
@tuespetre How do you determine whether a browser supports ES2015 before you deliver JS files to it? |
@mislav I use an approach like @philipwalton describes in his blog post:
|
@tuespetre I see; thanks for showing! 🙇 |
@josh I see in the changes that |
I don't really see the practical difference. Both are global registrations. The current implementation of the Custom Elements Registry doesn't provide any scoping mechanize. |
@josh the primary benefit of using the Any plans to move forward with this PR? 😸 |
Fixes maximum call stack size exceeded.
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.
@muan your changes look good here. Thanks! If you feel like we should iterate on V1 in master
, we can go ahead and merge this branch.
Transitioning to Custom Elements v1.
Reflect.construct
polyfill situation. @notwaldorf how is polymer implementing Custom Elements v1 on old browsers?import {LocalTimeElement} from 'time-elements'
is side-effect free. Also supportimport 'time-elements/define'
which registers the constructors on the current document.To: @dgraham @mislav
CC: @github/js @notwaldorf