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

Add naive custom element support #1249

Closed
wants to merge 1 commit into from

Conversation

mereskin-zz
Copy link

JSX will render <custom-element /> as custom-element(). Rendering it as CustomElement() sounds like a better idea, because it is syntactically correct. If we operate on an assumption, that custom elements names map to React displayNames with this convention, we can build React-driven web component:

/** @jsx React.DOM */
var MyComponent = React.createClass({
  render: function(){
    return (<p>Hello {this.props.name}</p>);
  }
});

var MyComponentPrototype = Object.create(HTMLElement.prototype);

MyComponentPrototype.attachedCallback = function(){
  var props = {};
  Array.prototype.forEach.call(this.attributes, function(attr){
    props[attr.name] = attr.value;
  });
  React.renderComponent(MyComponent(props), this);
};

document.registerElement('my-component', { prototype: MyComponentPrototype });

@syranide
Copy link
Contributor

It seems like a very weird convention for custom => custom but custom-element => CustomElement. I.e, the hyphen not only capitalizes the word after the hyphen (kind of makes sense), but also the capitalization of the entire name (does not make sense to me).

It also introduces amgibuity into JSX as <CustomElement /> and <custom-element /> are now identical, but neither is intuitively the right way.

@andreypopp
Copy link
Contributor

I think code above works without the patch?

@sophiebits
Copy link
Collaborator

(Tangentially related to #1240.)

@sophiebits
Copy link
Collaborator

Going to close this in favor of #1539, which is a little cleaner. Thanks for sending this in!

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

Successfully merging this pull request may close these issues.

5 participants