Skip to content

Commit

Permalink
Component: implement DI (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
jokade committed Mar 30, 2016
1 parent d89f884 commit d36fb4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/main/scala/biz/enef/angulate/Component.scala
Expand Up @@ -67,6 +67,9 @@ object Component {

val base = getJSBaseClass(parents)

val args = paramNames(params)
val diNames = args map ( _.toString )

val tree =
q"""{
@scalajs.js.annotation.JSExport($fullName)
Expand All @@ -76,12 +79,29 @@ object Component {
@scalajs.js.annotation.ScalaJSDefined
object ${name.toTermName} extends scalajs.js.Object {
def selector = "test"
def controller = js.Array((() => new $name(..$params)):js.Function)
def controller = js.Array(..$diNames,((..$params) => new $name(..$args)):js.Function)
def options = scalajs.js.Dictionary( "controller" -> controller, ..$annots )
}
}
"""

println(tree)
c.Expr[Any](tree)
}

// TODO: simpler, use generic function instead of local copy :)
def getDINames(params: Iterable[Tree]): Iterable[String] =
if(params.isEmpty) None
else
params map {
case q"$mods val $name: $tpe = $e" =>
val t = c.typecheck(tpe,c.TYPEmode).tpe
t.typeSymbol.annotations.map(_.tree).collectFirst{
case q"new $name( ..$params )" if name.toString == "scala.scalajs.js.annotation.JSName" => params.head match {
case Literal(Constant(x)) => x.toString
}
}.getOrElse(t.toString)
}

}
}
2 changes: 1 addition & 1 deletion src/main/scala/biz/enef/angulate/impl/MacroBase.scala
Expand Up @@ -11,7 +11,7 @@ import de.surfice.smacrotools.JsWhiteboxMacroTools
import scala.reflect.macros.whitebox


protected[angulate] abstract class MacroBase extends JsWhiteboxMacroTools {
protected[angulate] abstract class MacroBase {
val c: whitebox.Context
import c.universe._

Expand Down

0 comments on commit d36fb4d

Please sign in to comment.