diff --git a/build.sbt b/build.sbt index cecf3cc..1c8c645 100644 --- a/build.sbt +++ b/build.sbt @@ -19,7 +19,7 @@ lazy val root = project.in(file(".")). name := "scalajs-angulate", libraryDependencies ++= Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value, - "org.scala-js" %%% "scalajs-dom" % "0.7.1-SNAPSHOT" + "org.scala-js" %%% "scalajs-dom" % "0.7.0" ), resolvers += Resolver.sonatypeRepo("releases") ) diff --git a/project/plugins.sbt b/project/plugins.sbt index b576cc1..d5c8816 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,3 +1,3 @@ -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0-RC1") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.0-RC2") addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.2.5-RC1") diff --git a/src/main/scala/biz/enef/angular/core/Http.scala b/src/main/scala/biz/enef/angular/core/Http.scala index 677b396..d7e37c0 100644 --- a/src/main/scala/biz/enef/angular/core/Http.scala +++ b/src/main/scala/biz/enef/angular/core/Http.scala @@ -74,27 +74,27 @@ object HttpConfig { trait HttpPromise[T] extends js.Object { def success(callback: js.Function): HttpPromise[T] = js.native - def success(callback: js.Function1[js.Any, Unit]): this.type = js.native + def success(callback: js.Function1[js.Any, Unit]): HttpPromise[T] = js.native - def success(callback: js.Function2[js.Any, Int, Unit]): this.type = js.native + def success(callback: js.Function2[js.Any, Int, Unit]): HttpPromise[T] = js.native - def success(callback: js.Function3[js.Any, js.Any, Int, Unit]): this.type = js.native + def success(callback: js.Function3[js.Any, js.Any, Int, Unit]): HttpPromise[T] = js.native - def success(callback: js.Function4[js.Any, Int, js.Any, js.Any, Unit]): this.type = js.native + def success(callback: js.Function4[js.Any, Int, js.Any, js.Any, Unit]): HttpPromise[T] = js.native - def success(callback: js.Function5[js.Any, Int, js.Any, js.Any, js.Any, Unit]): this.type = js.native + def success(callback: js.Function5[js.Any, Int, js.Any, js.Any, js.Any, Unit]): HttpPromise[T] = js.native def error(callback: js.Function): HttpPromise[T] = js.native - def error(callback: js.Function1[js.Any, Unit]): this.type = js.native + def error(callback: js.Function1[js.Any, Unit]): HttpPromise[T] = js.native - def error(callback: js.Function2[js.Any, Int, Unit]): this.type = js.native + def error(callback: js.Function2[js.Any, Int, Unit]): HttpPromise[T] = js.native - def error(callback: js.Function3[js.Any, js.Any, Int, Unit]): this.type = js.native + def error(callback: js.Function3[js.Any, js.Any, Int, Unit]): HttpPromise[T] = js.native - def error(callback: js.Function4[js.Any, Int, js.Any, js.Any, Unit]): this.type = js.native + def error(callback: js.Function4[js.Any, Int, js.Any, js.Any, Unit]): HttpPromise[T] = js.native - def error(callback: js.Function5[js.Any, Int, js.Any, js.Any, UndefOr[String], Unit]): this.type = js.native + def error(callback: js.Function5[js.Any, Int, js.Any, js.Any, UndefOr[String], Unit]): HttpPromise[T] = js.native var `then`: js.Function3[js.Function, js.Function, js.Function, HttpPromise[T]] = js.native //var `then`: js.Function3[js.Function1[T,Unit],js.Function,js.Function,Unit] = js.native @@ -102,20 +102,7 @@ trait HttpPromise[T] extends js.Object { object HttpPromise { //------------------------- ANGULATE ENHANCEMENTS -------------------------- - final implicit class RichHttpPromise[T](self: HttpPromise[T]) { - /** - * The provided callback will be called when a successful response is available - * (response status codes between 200 and 299 are considered a success status). - * - * @note This is a scalajs-angulate enhancement. The response data provided to - * the callback will be cast to the specified type T. - * - * @param callback Callback function that will receive the response data as its first argument - * @tparam T Type of the response data object - */ - //def success[T](callback: (T) => Unit) : this.type = macro impl.HttpPromiseMacros.onSuccessWithType[T] - - //def onSuccess(pf: PartialFunction[Any,Unit]) : Unit = macro impl.HttpPromiseMacros.onSuccess + final implicit class RichHttpPromise[T](val self: HttpPromise[T]) extends AnyVal { def onSuccess(f: T => Unit): HttpPromise[T] = macro impl.HttpPromiseMacros.onSuccess diff --git a/src/main/scala/biz/enef/angular/core/impl/HttpMacros.scala b/src/main/scala/biz/enef/angular/core/impl/HttpMacros.scala index f5976ee..2ce4f65 100644 --- a/src/main/scala/biz/enef/angular/core/impl/HttpMacros.scala +++ b/src/main/scala/biz/enef/angular/core/impl/HttpMacros.scala @@ -31,8 +31,9 @@ protected[angular] class HttpPromiseMacros(val c: blackbox.Context) extends Macr def onSuccess(f: c.Tree) = { val T = f.tpe.typeArgs.head + val self = Select(c.prefix.tree, TermName("self")) val tree = q"""{val fun = $f - ${c.prefix}.success( (x: js.UndefOr[$T]) => fun(x.getOrElse(null)) )}""" + $self.success( (x: js.UndefOr[$T]) => fun(x.getOrElse(null)) )}""" if(logCode) printCode(tree) tree @@ -40,8 +41,11 @@ protected[angular] class HttpPromiseMacros(val c: blackbox.Context) extends Macr def onComplete(f: c.Tree) = { val T = f.tpe.typeArgs.head.typeArgs.head + + val self = Select(c.prefix.tree, TermName("self")) + val tree = q"""{val fun = $f - ${c.prefix}.success( ((x:js.UndefOr[$T]) =>fun($tSuccess(x.getOrElse(null)))) ). + $self.success( ((x:js.UndefOr[$T]) =>fun($tSuccess(x.getOrElse(null)))) ). error( (msg:Any,status:Int)=>fun($tFailure(new $tHttpError(msg.toString,status))) ) }""" if(logCode) printCode(tree) @@ -49,7 +53,8 @@ protected[angular] class HttpPromiseMacros(val c: blackbox.Context) extends Macr } def onFailure(f: c.Tree) = { - val tree = q"""${c.prefix}.error( (msg:Any,status:Int)=>$f(new $tHttpError(msg.toString,status)))""" + val self = Select(c.prefix.tree, TermName("self")) + val tree = q"""$self.error( (msg:Any,status:Int)=>$f(new $tHttpError(msg.toString,status)))""" if(logCode) printCode(tree) tree @@ -57,8 +62,9 @@ protected[angular] class HttpPromiseMacros(val c: blackbox.Context) extends Macr def map(f: c.Tree) = { val T = f.tpe.typeArgs(1) + val self = Select(c.prefix.tree, TermName("self")) val tree = q"""{import biz.enef.angular.core - val mapped = new core.impl.MappedHttpPromise(${c.prefix},$f) + val mapped = new core.impl.MappedHttpPromise($self,$f) mapped.asInstanceOf[core.HttpPromise[$T]] } """