xored / scala-js-react

ScalaJS interface for Facebook React
Apache License 2.0
133 stars 13 forks source link

Is it possible to declare the components we defined in XML? #11

Closed freewind closed 9 years ago

freewind commented 9 years ago

I see in the examples, we can just declare in XML with the standard HTML tags, like:

@scalax
  def render(self: This) = {
    <div>Hello {self.props.name}</div>
  }

Is it possible to use the components we defined? like:

@scalax
  def render(self: This) = {
    <MyComponent>Hello {self.props.name}</MyComponent>
  }
kanterov commented 9 years ago

It's not possible to use XML syntax for this; there is an example demonstrating embedding other components: https://github.com/xored/scala-js-react/blob/master/scalajs-react-examples/src/main/scala/com/xored/scalajs/react/examples/children/Children.scala.

freewind commented 9 years ago

Thanks, just wondering the reason of "It's not possible to use XML syntax". Is it because the macro provided by Scala is not power enough to implement it?

(I'm not familiar with Scala's macro, but really hope that's possible)

kanterov commented 9 years ago

It doesn't implement it, I found it not much practical while robust implementation isn't so easy because TypedReactspec#Props is a reference to a type. It doesn't have to be case class, or have single apply method, for example, define type Props = Unit.

freewind commented 9 years ago

Thanks !