Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to expose less internal API
Without: 180,735 With: 314,311 Increase: 133,576 (+74%) 2,257,187 → 252,498 - bench-big (fast) 458,880 → 117,304 - bench-big (full)
- Loading branch information
Showing
75 changed files
with
902 additions
and
759 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
core/js/src/main/scala/scalacss/defaults/PlatformExports.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package scalacss.defaults | ||
|
||
import org.scalajs.dom.document | ||
import org.scalajs.dom.raw.HTMLStyleElement | ||
import scalacss.internal.mutable.{StyleSheet, StyleSheetRegistry} | ||
import scalacss.internal.{Css, Env, Renderer} | ||
|
||
// ================ | ||
// ==== ==== | ||
// ==== JS ==== | ||
// ==== ==== | ||
// ================ | ||
|
||
object PlatformExports { | ||
|
||
def createStyleElement(styleStr: String): HTMLStyleElement = { | ||
val e = document.createElement("style").asInstanceOf[HTMLStyleElement] | ||
e.`type` = "text/css" | ||
e appendChild document.createTextNode(styleStr) | ||
e | ||
} | ||
|
||
def installStyle(style: HTMLStyleElement): Unit = | ||
document.head appendChild style | ||
|
||
|
||
class StyleElementRenderer(s: Renderer[String]) extends Renderer[HTMLStyleElement] { | ||
override def apply(css: Css) = | ||
createStyleElement(s(css)) | ||
} | ||
|
||
final class StyleSheetInlineJsOps(private val ss: StyleSheet.Inline) extends AnyVal { | ||
/** Turns this StyleSheet into a `<style>` and adds it to the document DOM. */ | ||
def addToDocument()(implicit s: Renderer[HTMLStyleElement], e: Env): Unit = | ||
installStyle(ss.render[HTMLStyleElement]) | ||
} | ||
|
||
final class StyleSheetRegistryJsOps(private val r: StyleSheetRegistry) extends AnyVal { | ||
/** Registered StyleSheets are turned into a `<style>` and added to the document DOM. */ | ||
def addToDocumentOnRegistration()(implicit s: Renderer[String], e: Env): Unit = | ||
r.onRegistrationN { ss => | ||
val styleStr = ss.map(_.render[String]).mkString("\n") | ||
val style = createStyleElement(styleStr) | ||
installStyle(style) | ||
} | ||
} | ||
} | ||
|
||
trait PlatformExports { | ||
|
||
implicit def toStyleSheetInlineJsOps(s: StyleSheet.Inline): PlatformExports.StyleSheetInlineJsOps = | ||
new PlatformExports.StyleSheetInlineJsOps(s) | ||
|
||
implicit def toStyleSheetRegistryJsOps(s: StyleSheetRegistry): PlatformExports.StyleSheetRegistryJsOps = | ||
new PlatformExports.StyleSheetRegistryJsOps(s) | ||
|
||
implicit final def cssStyleElementRenderer(implicit s: Renderer[String]): Renderer[HTMLStyleElement] = | ||
new PlatformExports.StyleElementRenderer(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package scalacss.internal | ||
|
||
import scala.annotation.elidable | ||
|
||
// ================ | ||
// ==== ==== | ||
// ==== JS ==== | ||
// ==== ==== | ||
// ================ | ||
|
||
object Platform { | ||
|
||
/** | ||
* Use the scalac `-Xelide-below` flag to switch from development- to production-mode. | ||
*/ | ||
@elidable(elidable.ASSERTION) | ||
@inline def DevMode: Boolean = | ||
true | ||
// @inline def DevMode: Boolean = | ||
// scalajs.LinkingInfo.developmentMode | ||
|
||
implicit def env: Env = | ||
Env.empty | ||
} |
6 changes: 3 additions & 3 deletions
6
...c/main/scala/scalacss/mutable/Mutex.scala → ...ala/scalacss/internal/mutable/Mutex.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
package scalacss.js | ||
|
||
import utest._ | ||
import scalacss._ | ||
import TestUtil._ | ||
|
||
import scala.scalajs.js.annotation.JSExport | ||
import utest._ | ||
|
||
@JSExport("PlatformJsTest") | ||
object PlatformJsTest extends TestSuite { | ||
|
||
@JSExport("test") | ||
def test: Unit = { | ||
def test(): Unit = { | ||
println(PlatformJs.value) | ||
println(JsEnv.value.platform) | ||
println(JsEnv.value.media) | ||
println(PlatformJsEnv.value.map(_.platform)) | ||
println(PlatformJsEnv.value.map(_.media)) | ||
} | ||
|
||
override val tests = TestSuite { | ||
test | ||
test() | ||
} | ||
} |
9 changes: 2 additions & 7 deletions
9
...ain/scala/scalacss/PlatformDefaults.scala → ...a/scalacss/defaults/PlatformExports.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
package scalacss | ||
package scalacss.defaults | ||
|
||
// ================= | ||
// ==== ==== | ||
// ==== JVM ==== | ||
// ==== ==== | ||
// ================= | ||
|
||
|
||
trait PlatformDefaults { | ||
|
||
implicit def env: Env = | ||
Env.empty | ||
} | ||
trait PlatformExports |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package scalacss.internal | ||
|
||
import scala.annotation.elidable | ||
|
||
// ================= | ||
// ==== ==== | ||
// ==== JVM ==== | ||
// ==== ==== | ||
// ================= | ||
|
||
object Platform { | ||
|
||
/** | ||
* Use the scalac `-Xelide-below` flag to switch from development- to production-mode. | ||
*/ | ||
@elidable(elidable.ASSERTION) | ||
@inline def DevMode: Boolean = | ||
true | ||
|
||
implicit def env: Env = | ||
Env.empty | ||
|
||
} |
6 changes: 3 additions & 3 deletions
6
...c/main/scala/scalacss/mutable/Mutex.scala → ...ala/scalacss/internal/mutable/Mutex.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.