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

Automate component registration for JSX components #282

Open
eduardolundgren opened this issue Oct 19, 2017 · 6 comments
Open

Automate component registration for JSX components #282

eduardolundgren opened this issue Oct 19, 2017 · 6 comments

Comments

@eduardolundgren
Copy link
Contributor

eduardolundgren commented Oct 19, 2017

It is verbose and error-prone forcing the developer to call ComponentRegistry.register.
Ideally, this should be automated by a transpilation step or a runtime operation.

With this change, the component definition will change from this

import {JSXComponent} from 'metal-jsx';
import {ComponentRegistry} from 'metal-component';

class Button extends JSXComponent {
}
ComponentRegistry.register(Button);

to this

import {JSXComponent} from 'metal-jsx';

class Button extends JSXComponent {
}
@yuchi
Copy link
Contributor

yuchi commented Oct 19, 2017

I leave my 2¢ here too: component registration is leaky (there’s a single component registry) and should happen exclusively when the developer understands the implications.

@yuchi
Copy link
Contributor

yuchi commented Oct 19, 2017

See errors such as:

customElements.define('x-x', class X extends HTMLElement {});
customElements.define('x-x', class X extends HTMLElement {});

Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry

@yuchi
Copy link
Contributor

yuchi commented Oct 19, 2017

Hint: it will happen when multiple versions of the same component are loaded in the page.

@eduardolundgren
Copy link
Contributor Author

@yuchi throw a runtime error if the component is already registered is a good suggestion to make the component registry less "leaky".

@yuchi
Copy link
Contributor

yuchi commented Oct 19, 2017

Actually that's what happens already. AFAIK it's in the spec.

@eduardolundgren
Copy link
Contributor Author

@yuchi I meant, throwing an error on Metal.js component registry, similar to what you described on custom elements. Wasn't that your suggestion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants