Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix #2948: Remove js.use(x).as[T] #2959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions library/src/main/scala/scala/scalajs/js/Using.scala

This file was deleted.

103 changes: 0 additions & 103 deletions library/src/main/scala/scala/scalajs/js/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,107 +130,4 @@ package object js {
"because you tried to run Scala.js binaries on the JVM. Make sure you " +
"are using the JVM version of the libraries.")

/** Allows to cast a value to a facade trait in a type-safe way.
*
* Use as follows:
* {{{
* js.use(x).as[MyFacade]
* }}}
*
* Note that the method calls are only syntactic sugar. There is no overhead
* at runtime for such an operation. Using `use(x).as[T]` is strictly
* equivalent to `x.asInstanceOf[T]` if the compile time check does not fail.
*
* This method supports both Scala classes with exports and facade types
* which are structurally equivalent.
*
* == Examples ==
* Given the following facade type:
* {{{
* trait MyFacade extends js.Object {
* def foo(x: Int): String = js.native
* val bar: Int = js.native
* }
* }}}
*
* We show a couple of examples:
* {{{
* class MyClass1 {
* @JSExport
* def foo(x: Int): String = x.toString
*
* @JSExport
* val bar: Int = 1
* }
*
* val x1 = new MyClass1
* js.use(x1).as[MyFacade] // OK
* }}}
*
* Note that JS conventions apply: The `val bar` can be implemented with a
* `def`.
*
* {{{
* class MyClass2 {
* @JSExport
* def foo(x: Int): String = x.toString
*
* @JSExport
* def bar: Int = 1 // def instead of val
* }
*
* val x2 = new MyClass2
* js.use(x2).as[MyFacade] // OK
* }}}
*
* Missing methods or methods with wrong types will cause a compile-time
* failure.
*
* {{{
* class MyClass3 {
* @JSExport
* def foo(x: String): String = x.toString // wrong type signature
*
* // bar is missing
* }
*
* val x3 = new MyClass3
* js.use(x2).as[MyFacade] // Fails: bar is missing and foo has wrong type
* }}}
*
* Methods must be exported, otherwise they are not taken into consideration.
*
* {{{
* class MyClass4 {
* def foo(x: Int): String = x.toString
*
* @JSExport
* def bar: Int = 1 // def instead of val
* }
*
* val x4 = new MyClass4
* js.use(x4).as[MyFacade] // Fails, foo is missing
* }}}
*
* Other facade types can also be used
*
* {{{
* trait MyOtherFacade extends js.Object {
* def foo(x: Any): String = js.native
* val bar: Int = js.native
* def otherMethod(): Unit = js.native
* }
*
* val x5: MyOtherFacade = // ...
* js.use(x5).as[MyFacade] // OK
* }}}
*
* == Restrictions ==
* - Facade types may only be traits and not have any class ancestors
* - Polymorphic methods are currently not supported
* - Facade types defining an apply method cannot used (this is a JavaScript
* restriction).
*/
def use[A](x: A): Using[A] = new Using[A](x)

}
53 changes: 0 additions & 53 deletions library/src/main/scala/scala/scalajs/macroimpls/Compat210.scala

This file was deleted.

This file was deleted.

97 changes: 0 additions & 97 deletions library/src/main/scala/scala/scalajs/macroimpls/JSMembers.scala

This file was deleted.

Loading