Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Handler[T,R] should be newable/extendable in newer Scala.js #84

Merged
merged 2 commits into from
Feb 18, 2020

Conversation

exoego
Copy link
Owner

@exoego exoego commented Feb 18, 2020

Closes #83

A Scala.js-defined JS object cannot directly extend a native JS trait in:

  • Scala.js 0.6 with -P:scalajs:sjsDefinedByDefault option
  • Scala.js 1.0

Currently, Handler extends js.Function3, so users in such setup cannot extend Handler or construct (new Handler {}).

This PR changes Handler[TEvent, TResult] into a Scala.js-defined trait.
Note that Handler and AsyncHandler is now clearly distinguished.

trait Handler[TEvent, TResult] extends js.Object {
  @JSName("apply")
  def apply(event: TEvent, context: Context, callback: Callback[TResult]): Unit
}
trait AsyncHandler[TEvent, TResult] extends js.Object {
  @JSName("apply")
  def apply(event: TEvent, context: Context): js.Promise[TResult]
}

so that it is newable/extendable

import scala.scalajs.js
import net.exoego.facade.aws_lambda._

object MyFirstLambda extends APIGatewayProxyHandler {
  @js.annotation.JSName("apply")
  override def apply(event: APIGatewayEvent, context: Context, callback: Callback[ProxyResult]): Unit = ???
}
object MyFirstAsyncLambda extends AsyncAPIGatewayProxyHandler {
  @js.annotation.JSName("apply")
  override def apply(event: APIGatewayEvent, context: Context): js.Promise[APIGatewayProxyResult]  = ???
}

@exoego exoego added the enhancement New feature or request label Feb 18, 2020
@exoego exoego changed the title Handler[T,R] should be newable/extendable Handler[T,R] should be newable/extendable in newer Scala.js Feb 18, 2020
@exoego exoego merged commit f9ad03e into master Feb 18, 2020
@exoego exoego deleted the fix-handler branch February 18, 2020 02:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile error when extending native JS trait APIGatewayProxyHandler
1 participant