Skip to content

Commit

Permalink
Merge pull request #21 from gregghz/input-annotation
Browse files Browse the repository at this point in the history
Adds @input() similar to typescript API
  • Loading branch information
jokade authored Jul 3, 2016
2 parents c581f20 + 65c2791 commit 913467c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/main/scala/angulate2/Component.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,40 @@ object Component {

def modifiedDeclaration(classDecl: ClassDef) = {
val parts = extractClassParts(classDecl)

import parts._

// load debug annotation values (returns default config, if there is no @debug on this component)
val debug = getDebugConfig(modifiers)

val inputStrLiterals = body collect {
case q"@Input() var $iName: $iType = $iRhs" => iName.toString
case q"@Input($extName) var $iName: $iType = $iRhs" => extName match {
case Literal(Constant(value)) => s"$iName:$value"
case currentTree => c.abort(currentTree.pos, "@Input() parameter must be a literal String")
}
}


val objName = fullName + "_"
val componentAnnotationParams = extractAnnotationParameters(c.prefix.tree,annotationParamNames) collect {
val allComponentAnnotationParams = extractAnnotationParameters(c.prefix.tree, annotationParamNames).collect {
case (name,Some(value)) => q"${Ident(TermName(name))} = $value"
}

val (nonInputAnnotationParams, inputAnnotationParams) = allComponentAnnotationParams.partition {
case q"inputs = $v" => false
case _ => true
}

val inputs = inputAnnotationParams match {
case q"inputs = js.Array(..$ins)" :: Nil =>
q"inputs = scalajs.js.Array(..${ins ++ inputStrLiterals.map(s => Literal(Constant(s)))})"
case _ =>
q"inputs = scalajs.js.Array(..$inputStrLiterals)"
}

val componentAnnotationParams = Iterable(inputs) ++ nonInputAnnotationParams

val parameterAnnot = parameterAnnotation(fullName,params)

// string to be written to the annotations.js file
Expand Down
7 changes: 7 additions & 0 deletions src/main/scala/angulate2/Input.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package angulate2

import scala.annotation.StaticAnnotation

class Input() extends StaticAnnotation {
def this(externalName: String) = this()
}

0 comments on commit 913467c

Please sign in to comment.