Skip to content

Commit

Permalink
Merge pull request #1 from Jasper-M/feature-automatic-implicit-conver…
Browse files Browse the repository at this point in the history
…sion

Added implicit conversion to companion object of JSOptionBuilder
  • Loading branch information
jducoeur committed Apr 2, 2015
2 parents e81bcd3 + fb21e51 commit 82cf04b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local.properties
.classpath
.settings/
.loadpath
.cache

# External tool builders
.externalToolBuilders/
Expand Down
8 changes: 7 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ pomExtra := (
<url>https://github.com/jducoeur/</url>
</developer>
</developers>
<contributors>
<contributor>
<name>Jasper Moeys</name>
<url>https://github.com/Jasper-M/</url>
</contributor>
</contributors>
)

pomIncludeRepository := { _ => false }
pomIncludeRepository := { _ => false }
11 changes: 11 additions & 0 deletions src/main/scala/org/querki/jsext/JSOptionBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import scala.scalajs.js

import js.JSConverters._

import scala.language.implicitConversions

/**
* Helper class for defining strongly-typed "options" classes to pass into Scala.js facades.
* This approach is particularly helpful for jQuery-based facades, which often take very
Expand Down Expand Up @@ -42,3 +44,12 @@ abstract class JSOptionBuilder[T <: js.Object, B <: JSOptionBuilder[T, _]](copy:
s"""{\n${dict.keys.map{ key => s" $key = ${dict(key).toString}"}.mkString("\n")}\n}"""
}
}

object JSOptionBuilder {

/**
* Automatically extract the result from a JSOptionBuilder when necessary.
*/
implicit def builder2Options[T <: js.Object](builder: JSOptionBuilder[T,_]): T = builder._result

}

0 comments on commit 82cf04b

Please sign in to comment.