Build truly native cross platform (web,ios,android) apps using scalajs and react, react-native ,This project moved to new organization : https://github.com/scalajs-react-interface/sri#sri, new chat room : https://gitter.im/scalajs-react-interface/sri
class ReactFactory[A, P, S](val ctor: js.Dynamic) {
def typed = ctor.asInstanceOf[ReactTypedConstructor[P, S]]
def createElement(props: P): ReactElementU[P, S] = ...
// all the createElement variants
}
object ReactFactory {
def apply[A <: ReactComponentBase](implicit ct: ConstructorTag[A]) = new ReactFactory[A, A#Props, A#State](ct.constructor)
Now you can write ReactFactory[MyComponent].createElement(...)
Note: createElement is necessary, we can't just call it apply and use function application syntax, since that would get interpreted as filling the implicit parameter list.
Alternatively, createElement etc. could be modified to something like
First, create a base trait
then make ReactComponent extend it and fill in type members to its type arguments.
Then you can have
However I would take it a step further:
Now you can write
ReactFactory[MyComponent].createElement(...)
Note: createElement is necessary, we can't just call it
apply
and use function application syntax, since that would get interpreted as filling the implicit parameter list.Alternatively, createElement etc. could be modified to something like
(or take ReactFactory implicitly as a typeclass).