Olical / react-faux-dom

DOM like structure that renders to React (unmaintained, archived)
http://oli.me.uk/2015/09/09/d3-within-react-the-right-way/
The Unlicense
1.21k stars 87 forks source link

Support for JSX? #34

Closed canadaduane closed 8 years ago

canadaduane commented 8 years ago

I'm a bit surprised that the faux DOM createElement method doesn't support the same method signature as regular React.createElement:

ReactElement.createElement = function (type, config, children) {

ReactFauxDOM:

  createElement: function (nodeName) {

As a result, it appears it isn't possible to actually swap ReactFauxDOM in for React, and use JSX:

  render () {
    var _React = React;
    React = ReactFauxDOM;

    var result = (
      <div className="ViewsHistogram box">
        Hello
      </div>
    );

    React = _React;
    return result.toReact();
  }

(The className and Hello text are ignored by ReactFauxDOM).

Is there a reason for this? Why not use the same method signature, and get JSX support for free?

Olical commented 8 years ago

I wrote the API like this to follow the existing document.createElement API. The goal was to follow the DOM API exactly, but just enough for it to work with D3 (for starters).

This was partially so you could avoid using JSX for something that D3 is quite good at, turning data into some form of complex document. (data driven documents). Turning JSX -> DOM -> JSX (essentially) is a strange round trip in my opinion.

This isn't supposed to be a rendering target for JSX, it's an alternative to JSX. JSX just compiles to function calls which create a React DOM. ReactFauxDOM is mutated then compiled to React DOM.

They're not really compatible with each other, they're options depending on how you are building your React DOM.

canadaduane commented 8 years ago

Got it. I misunderstood. Thank you!

Olical commented 8 years ago

No problem! Closing this now, I hope that helped :)