Closed andreawyss closed 8 years ago
Can you add a test for this?
This only work with custom element V1. At the same time this is to work around the typescript issue 7574 that is being work on: https://github.com/Microsoft/TypeScript/issues/7574
I don't know how to add custom element V1 this to the test. This is what I have so far:
describe('reactify-with-tag-name', () => { it('should be able to reactify with tagName', () => {
window.customElements.define('x-comp', {
prototype: Object.create(HTMLElement.prototype)
});
const Comp = reactify("x-comp", {React, ReactDOM});
ReactDOM.render(React.createElement(Comp), window.fixture);
expect(Comp.displayName).to.equal('XComp');
}); });
I think your test looks good. Also it doesn't look like it's just for typescript? It's pretty generic (CustomElement
could be either a string or class).
I agree it is very generic but, customElement V1 or a customElement V1 polyfill must be in place. My PR code uses customElements.get() and the test uses customElements.define(). The problem is that I don't know how to add the polyFill to the test. The test fails without a polyfill like this one: https://github.com/webcomponents/custom-elements
@andreawyss you can import https://github.com/skatejs/web-components to the package.json and then import it in the main test entry point (test/unit.js
).
I've thought about doing this in the past but decided against it for a couple reasons:
connectedCallback
is fired. You also shouldn't be doing any heavy lifting until the component is actually in the DOM. Unfortunately these are best-practices that have largely been left out of the greater web component ecosystem docs and resources.observedAttributes
et al.There's currently no spec on how to get the localName
of a component using only the constructor and I'm somewhat hesitant to add this because of point 2.
I've raised an issue and a modest proposal in https://github.com/w3c/webcomponents/issues/566 for doing this without having to construct the element.
Any counter arguments? Thoughts? This really feels like something TypeScript needs to fix, however, including the polyfill might fix it.
I agree that this is just a workaround for a TypeScript bug. This should be fixed soon in next version of TypeScript since this pull request is addressing this issue: https://github.com/Microsoft/TypeScript/pull/10762
Therefore I will Close this PR. Thank you.
Awesome! Thanks, @andreawyss!
Allows to pass to reactify the tagName instead of the CustomElement class. Avoids creating an instance of the component just to get the tagName. Makes it possible to use this with Web.Components written in TypeScript.