Skip to content

Add XML style JSX namespacing support using @jsxns docblock comment. #1221

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

Closed
wants to merge 2 commits into from
Closed

Conversation

percyhanna
Copy link

Adds support for using XML namespaces in JSX to refer to custom defined identifiers in a @jsxns docblock comment. Can make a namespace refer to any JS identifier.

/**
 * @jsx React.DOM
 * @jsxns {"UI": "MyApp.UI", "External": "External"}
 */

React.createClass({
  render: function() {
    return (
      <UI:Component />
    );
  }
});

Compiles to:

React.createClass({
  render: function() {
    return (
      MyApp.UI.Component(null )
    );
  }
});

Should address most of the concerns and patterns mentioned in #221.

Included some basic tests for validating namespace definition and usage.

@chenglou
Copy link
Contributor

chenglou commented Mar 5, 2014

@petehunt

@percyhanna
Copy link
Author

Also was unsure on placement of tests, I put them where I thought they were best suited, but am open to relocating them to somewhere else.

@percyhanna
Copy link
Author

Hmm, not initially clear to me why Travis environment was getting a different error being thrown than in my local environment. I've changed it to a generic .toThrow() expectation for now, but would appreciated any advice if someone knows why there was a difference.

Local: 'undefined' is not a function (evaluating 'SampleNamespace.ComponentC(null )')
Travis: Object #<Object> has no method 'ComponentC'

Based on the error messages, it seems that it's a difference between running SampleNamespace.ComponentC(null) vs. new SampleNamespace.ComponentC(null), but I'm not sure why the compiled JSX would be different.

@syranide
Copy link
Contributor

syranide commented Mar 5, 2014

Discussed at length in #760

@percyhanna
Copy link
Author

I hadn't noticed the extensiveness of that discussion before I began working on the PR. The syntax of defining the namespaces could be easily changed, if an alternate is desired.

@zpao
Copy link
Member

zpao commented Mar 5, 2014

Thanks for taking a stab at this. We're going to nail down our stance on namespacing in JSX and the strategy we want to follow ASAP.

@magalhas
Copy link

magalhas commented Mar 5, 2014

👍

@kendagriff
Copy link

+1 I also just got started on React.js, and almost immediately ran into wanting namespacing support in JSX.

@LBRapid
Copy link

LBRapid commented Mar 12, 2014

👍 Namespacing support would be splendid.

@percyhanna
Copy link
Author

Closing in favour of proposed fix in #760.

@percyhanna percyhanna closed this Mar 14, 2014
@percyhanna percyhanna deleted the jsxns branch November 1, 2014 05:28
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.

7 participants