Comments (16)
dear all, please give https://github.com/WebReflection/document-register-element/blob/v1/build/document-register-element.max.js a shot and tell me how it goes.
It's V1 for browsers that haven't fully implemented specs yet, and it's based on V0 which is battle-tested.
It's also backward compatible with V0 to help migrating between versions.
Caveat
Having upgrades within classes constructors is basically impossible to do via vanilla JS.
Accordingly, the constructor should return an upgraded version of itself when some initialisation is needed.
The easiest way I've found is compatible with both ES6 native classes and good old ES3 functions.
The hack is straight forward:
class MyElement extends HTMLElement {
constructor(self) {
// upgrade the context
self = super(self);
// initialise through `self` instead of `this`
// overwrite the default returned context
return self;
}
}
Being not elegant but working way better than a pointless, potentially error-trigger call like done in current webcomponentjs, it's also possible to "beautify" the pattern through extends.
// our new base class
class HTMLCustomElement extends HTMLElement {
constructor(_) { return (_ = super(_)).init(), _; }
init() { /* override as you like */ }
}
// create any other class inheriting HTMLCustomElement
class MyElement extends HTMLCustomElement {
init() {
// any initialization logic
this.setAttribute('test', 'OK');
}
}
Native extends supported
I don't care about WebKit stubborn position on native extends (actually I do and I've patched it indeed) but these should be fully supported in my V1.
class MyLink extends HTMLAnchorElement {}
customElements.define('my-link', MyLink, {extends: 'a'});
var a = new MyLink();
a.href = 'http://google.com/';
a.textContent = 'search stuff';
document.body.appendChild(a);
// <a is="my-link">search stuff</a>
Please let me know what you think so I can eventually publish and bump to v1.0.0 sooner than later.
Best Regards
from document-register-element.
OK ... when I've created this poly I thought things were OK and I bet on public specs.
It looks like things aren't even finished yet ... I'm not sure I want to repeat the same mistake twice.
Can anyone confirm the current status is the one that everyone agreed about?
I'd rather wait than ship yet another intermediate API that won't be available cross browsers.
This stuff reminds me the flex-box story, we're changing methods instead of prefixes 😆
from document-register-element.
It's already working, like tests show. WebKit should listen to users (their customers) and read specs, which is what I've done as polyfill author.
If they'll decide to never implement the is
attribute, then WebKit will switch to hybrid mode: simple extends will be based on native customElements
and native extends with the is
attribute will be polyfilled.
Everybody wins ;-)
from document-register-element.
As I understand it, the major changes are listed in WICG/webcomponents#405.
From a user's perspective, it seemed like the API changes were fairly limited:
- Uses
defineElement
instead ofregisterElement
- Removed
createdCallback
[…]
should construct the element using its constructor
However, a brief conversation with Domenic suggests there's more stuff going on under the hood:
http://logs.glob.uno/?c=freenode%23whatwg&s=1+Jun+2016#c996899
That's about the extent of my own understanding right now, but I'd certainly be interested in a lightweight v1 polyfill.
from document-register-element.
Uses defineElement instead of registerElement
It's actually now
window.customeElements.define('foo-bar', { ... })
Here's the latest (with some examples): https://w3c.github.io/webcomponents/spec/custom/
from document-register-element.
since you're asking, I guess you know it better than me, since I thought this one was the v1 already.
Do you think V1 can be built on top of this one?
Do you know what are major differences between V1 and this one?
I'm not into "polyfills" that much lately so any quick help to speed up decisions and provide an ETA would help.
Thanks
from document-register-element.
The v1 implementation is coming along over at the webcomponentsjs repo: https://github.com/webcomponents/webcomponentsjs/tree/v1/src/CustomElements/v1
I just added Shadow DOM v1 support last night. We have lots of testing to do, and I need to go over the spec again with a fine toothed comb (which I haven't yet done since it was merged into the HTML and DOM specs), but it should be fairly complete at this point. The whole polyfill weighs in at 1.7k gzipped.
from document-register-element.
Do you think V1 can be built on top of this one?
Yeah, I think so. Some ideas around that were mentioned here: skatejs/skatejs#563
from document-register-element.
From the aforementioned conversation with Domenic:
<FND> can WICG/webcomponents#405 be considered final?
<Domenic> FND: yes; custom elements have been upstreamed into HTML (and parts into DOM). See https://html.spec.whatwg.org/multipage/scripting.html#custom-elements.
from document-register-element.
+1 for implementing v1
All the browser vendors is actively working on it(except for Edge)
Safari
Chrome
Firefox
from document-register-element.
I guess we summarized @justinfagnani solution in here:
https://mobile.twitter.com/WebReflection/status/743936414895702016
feel free to use his effort in case you don't care about other browsers supported in here that never made it on Polymer
from document-register-element.
Related discussion WICG/webcomponents#509
from document-register-element.
I want to +1 this, and offer any help that is needed.
from document-register-element.
Update I previously forgot to push latest changes, which I've done now.
I've also tested against all previously supported devices for real, they are all green.
Here you can find the Custom Elements V1 live test page
from document-register-element.
I've published V1 which fixes this issue
from document-register-element.
short question @WebReflection about Webkit native extends. Do I understand it right, that you polyfill the is="custom-element"
attribute for Webkit?
from document-register-element.
Related Issues (20)
- LifeCycle events order of nested custom elements inconsistent across Chrome and Firefox HOT 18
- Built-in elements don't work in Firefox HOT 6
- TypeError: new.target does not define a custom element HOT 3
- document.registerElement is deprecated and will be removed in M73 HOT 3
- Post-install script slowness HOT 3
- appreciate your feedback for custom element diagram HOT 8
- [Uncaught DOMException: Failed to execute 'registerElement' on 'Document'] when used in Chrome Extension HOT 16
- Functions are not evaluated in connectedCallback HOT 1
- `this` reference in contructor broken HOT 14
- Multiple instances of the polyfill leads to unexpected behaviour HOT 1
- error ""Failed to construct 'HTMLElement': Please use the 'new' operator"" when using with Angular/elements 8.2.0 HOT 2
- Refreshing a document inside an iframe which loads d-r-e breaks the polyfill and leaves document.createElement as undefined HOT 15
- `attributeChangedCallback()` bound value is invalid HOT 15
- Add DRE to Polyfill.io service HOT 1
- [QUESTION] Unable to get property '_isMounted' of undefiened. HOT 1
- TypeError - Object doesn't support property or method 'registerElement' HOT 3
- Time to compare again? (webcompents/custom-elements) HOT 2
- Polyfill does not seem to be working in IE 11 HOT 6
- postinstall fails in noexec enviornment HOT 1
- We unable to install latest version @1.14.7 HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from document-register-element.