@@ -2,36 +2,22 @@ package japgolly.scalajs.react.component
22
33import scala .scalajs .js
44import japgolly .scalajs .react .internal ._
5- import japgolly .scalajs .react .{Callback , Children , CtorType , Key , PropsChildren , vdom , raw => RAW }
5+ import japgolly .scalajs .react .{Callback , Children , CtorType , PropsChildren , vdom , raw => RAW }
66
77object Js extends JsBaseComponentTemplate [RAW .ReactClass ] {
88
9- def apply [P <: js.Object , C <: Children , S <: js.Object ](r : RAW .ReactClass )
10- (implicit s : CtorType .Summoner [P , C ]): Component [P , S , s.CT ] =
9+ def apply [P <: js.Object , C <: Children , S <: js.Object ](r : RAW .ReactClass )(implicit s : CtorType .Summoner [P , C ]): Component [P , S , s.CT ] =
1110 component[P , C , S ](r)(s)
1211
13- def apply [P <: js.Object , C <: Children , S <: js.Object ](name : String )
14- (implicit s : CtorType .Summoner [P , C ]): Component [P , S , s.CT ] = {
15- val reactClass = findInScope(name.split('.' ).toList) match {
16- case Some (x : js.Function ) => x
12+ def apply [P <: js.Object , C <: Children , S <: js.Object ](d : js.Dynamic )(implicit s : CtorType .Summoner [P , C ]): Component [P , S , s.CT ] =
13+ apply[P , C , S ](d.asInstanceOf [RAW .ReactClass ])(s)
14+
15+ def apply [P <: js.Object , C <: Children , S <: js.Object ](name : String )(implicit s : CtorType .Summoner [P , C ]): Component [P , S , s.CT ] =
16+ JsUtil .evalName(name) match {
17+ case Some (d : js.Function ) => apply[P , C , S ](d)(s)
1718 case Some (_) => throw new IllegalArgumentException (s " React constructor $name is not a function " )
1819 case None => throw new IllegalArgumentException (s " React constructor $name is not defined " )
1920 }
20- apply[P , C , S ](reactClass)(s)
21- }
22-
23- private [this ] def findInScope (path : List [String ], scope : js.Dynamic = js.Dynamic .global): Option [js.Dynamic ] = {
24- path match {
25- case Nil => Some (scope)
26- case name :: tail =>
27- val nextScope = scope.selectDynamic(name).asInstanceOf [js.UndefOr [js.Dynamic ]].toOption
28- nextScope.flatMap(findInScope(tail, _))
29- }
30- }
31-
32- def apply [P <: js.Object , C <: Children , S <: js.Object ](d : js.Dynamic )
33- (implicit s : CtorType .Summoner [P , C ]): Component [P , S , s.CT ] =
34- apply[P , C , S ](d.asInstanceOf [RAW .ReactClass ])(s)
3521
3622 // ===================================================================================================================
3723
0 commit comments