本文整理汇总了Scala中scala.scalajs.js.annotation.JSExportTopLevel类的典型用法代码示例。如果您正苦于以下问题:Scala JSExportTopLevel类的具体用法?Scala JSExportTopLevel怎么用?Scala JSExportTopLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSExportTopLevel类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: WebDemoUIEntry
//设置package包名称以及导入依赖的类
package webdemo
import suzaku.platform.web.{WebWorkerTransport, WorkerClientTransport}
import org.scalajs.dom
import org.scalajs.dom.raw.Worker
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
@JSExportTopLevel("WebDemoUIEntry")
object WebDemoUIEntry {
var transport: WebWorkerTransport = _
@JSExport
def entry(workerScript: String): Unit = {
// create the worker to run our application in
val worker = new Worker(workerScript)
// create the transport
transport = new WorkerClientTransport(worker)
// listen to messages from worker
worker.onmessage = onMessage _
new WebDemoUI(transport)
}
private def debugPrint(data: Array[Byte]): Unit = {
data.grouped(16).foreach { d =>
val hex = d.map(c => "%02X " format (c & 0xFF)).mkString
val str = d
.collect {
case ascii if ascii >= 0x20 && ascii < 0x80 => ascii
case _ => '.'.toByte
}
.map(_.toChar)
.mkString
println(hex.padTo(16 * 3, ' ') + str)
}
}
def onMessage(msg: dom.MessageEvent) = {
msg.data match {
case buffer: ArrayBuffer =>
transport.receive(buffer)
case _ => // ignore other messages
}
}
}
示例2: WebDemoAppEntry
//设置package包名称以及导入依赖的类
package webdemo
import suzaku.platform.web.{WebWorkerTransport, WorkerTransport}
import org.scalajs.dom
import org.scalajs.dom.raw.DedicatedWorkerGlobalScope
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.typedarray.{ArrayBuffer, TypedArrayBuffer}
@JSExportTopLevel("WebDemoAppEntry")
object WebDemoAppEntry {
import DedicatedWorkerGlobalScope.self
var transport: WebWorkerTransport = _
@JSExport
def entry(): Unit = {
// create transport
transport = new WorkerTransport(self)
// receive WebWorker messages
self.onmessage = onMessage _
// create the actual application
val app = new WebDemoApp(transport)
}
private def debugPrint(data: Array[Byte]): Unit = {
data.grouped(16).foreach { d =>
val hex = d.map(c => "%02X " format (c & 0xFF)).mkString
val str = d
.collect {
case ascii if ascii >= 0x20 && ascii < 0x80 => ascii
case _ => '.'.toByte
}
.map(_.toChar)
.mkString
println(hex.padTo(16 * 3, ' ') + str)
}
}
def onMessage(msg: dom.MessageEvent) = {
msg.data match {
case buffer: ArrayBuffer =>
transport.receive(buffer)
case _ => // ignore other messages
}
}
}
示例3: PerfUIEntry
//设置package包名称以及导入依赖的类
package perftest
import org.scalajs.dom
import org.scalajs.dom.raw.Worker
import suzaku.platform.web.{WebWorkerTransport, WorkerClientTransport}
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.typedarray.ArrayBuffer
@JSExportTopLevel("PerfUIEntry")
object PerfUIEntry {
var transport: WebWorkerTransport = _
@JSExport
def entry(workerScript: String): Unit = {
// create the worker to run our application in
val worker = new Worker(workerScript)
// create the transport
transport = new WorkerClientTransport(worker)
// listen to messages from worker
worker.onmessage = onMessage _
new PerfUI(transport)
}
private def debugPrint(data: Array[Byte]): Unit = {
data.grouped(16).foreach { d =>
val hex = d.map(c => "%02X " format (c & 0xFF)).mkString
val str = d
.collect {
case ascii if ascii >= 0x20 && ascii < 0x80 => ascii
case _ => '.'.toByte
}
.map(_.toChar)
.mkString
println(hex.padTo(16 * 3, ' ') + str)
}
}
def onMessage(msg: dom.MessageEvent) = {
msg.data match {
case buffer: ArrayBuffer =>
transport.receive(buffer)
case _ => // ignore other messages
}
}
}
示例4: PerfAppEntry
//设置package包名称以及导入依赖的类
package perftest
import org.scalajs.dom
import org.scalajs.dom.raw.DedicatedWorkerGlobalScope
import suzaku.platform.web.{WebWorkerTransport, WorkerTransport}
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
import scala.scalajs.js.typedarray.ArrayBuffer
@JSExportTopLevel("PerfAppEntry")
object PerfAppEntry {
import DedicatedWorkerGlobalScope.self
var transport: WebWorkerTransport = _
@JSExport
def entry(): Unit = {
// create transport
transport = new WorkerTransport(self)
// receive WebWorker messages
self.onmessage = onMessage _
// create the actual application
val app = new PerfApp(transport)
}
private def debugPrint(data: Array[Byte]): Unit = {
data.grouped(16).foreach { d =>
val hex = d.map(c => "%02X " format (c & 0xFF)).mkString
val str = d
.collect {
case ascii if ascii >= 0x20 && ascii < 0x80 => ascii
case _ => '.'.toByte
}
.map(_.toChar)
.mkString
println(hex.padTo(16 * 3, ' ') + str)
}
}
def onMessage(msg: dom.MessageEvent) = {
msg.data match {
case buffer: ArrayBuffer =>
transport.receive(buffer)
case _ => // ignore other messages
}
}
}
示例5: JSLogger
//设置package包名称以及导入依赖的类
package wvlet.log
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
@JSExportTopLevel("wvlet.log")
object JSLogger {
@JSExport
def setDefaultLogLevel(level:String) : Boolean = {
Logger.setDefaultLogLevel(LogLevel(level))
true
}
@JSExport
def setLogLevel(loggerName:String, level:String) : Boolean = {
Logger(loggerName).setLogLevel(LogLevel(level))
true
}
}
示例6: Main
//设置package包名称以及导入依赖的类
package autosteamgifts.background
import autosteamgifts.background.check.Checker
import autosteamgifts.{AutoEnterSettingNotification, GiveawayEndingNotification}
import chromex.runtime.{OnInstalledDetails, OnInstalledReason}
import org.scalajs.dom.window.console
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
@JSExportTopLevel("autosteamgifts.Background")
object Main {
private val MessageReceivers = Seq(GameRating, AutoEnterSettingNotification)
@JSExport
def main(): Unit = {
setOnInstalledListener()
setOnMessageListener()
Checker.setListener()
Checker.setAlarm()
GiveawayEndingNotification.setListeners()
}
private def setOnInstalledListener(): Unit = {
chromex.runtime.onInstalled.addListener { details: OnInstalledDetails =>
console.log("onInstalled listener was triggered with", details)
if (details.reason == OnInstalledReason.Install) {
chromex.runtime.openOptionsPage()
}
}
}
private def setOnMessageListener(): Unit = {
chromex.runtime.onMessage.addListener { (message, sender, sendResponse) =>
val messageDict = message.asInstanceOf[js.Dictionary[_]]
val messageType = messageDict("type")
MessageReceivers.find { _.MessageType == messageType } match {
case Some(receiver) =>
receiver.receiveMessage(messageDict, sendResponse)
case None =>
console.error("Unknown message:", message)
false
}
}
}
}
示例7: Login
//设置package包名称以及导入依赖的类
package pages
import API._
import API.Models._
import org.scalajs.dom
import org.scalajs.dom._
import scala.concurrent._
import ExecutionContext.Implicits.global
import scala.scalajs.js.JSON
import scala.scalajs.js.annotation.JSExportTopLevel
import scala.util._
class Login {}
object Login {
@JSExportTopLevel("login")
def login(): Unit = {
val credentials = new Credentials(
document.getElementById("login-email").asInstanceOf[html.Input].value,
document.getElementById("login-password").asInstanceOf[html.Input].value
)
API.login(credentials).onComplete {
case Success(req) =>
val token = req.getResponseHeader("Authorization")
headers += ("Authorization" -> token)
document.cookie = "Authorization=" + token
document.location.pathname = "/"
case Failure(e: dom.ext.AjaxException) =>
Utils.addAlert("danger", JSON.parse(e.xhr.responseText).selectDynamic("message").asInstanceOf[String])
}
}
@JSExportTopLevel("register")
def register(): Unit = {
val user = new User(
document.getElementById("register-email").asInstanceOf[html.Input].value,
document.getElementById("register-fullname").asInstanceOf[html.Input].value,
document.getElementById("register-password").asInstanceOf[html.Input].value,
document.getElementById("register-currency").asInstanceOf[html.Input].value
)
API.register(user).onComplete {
case Success(resp) =>
val token = resp.getResponseHeader("Authorization")
headers += ("Authorization" -> token)
document.cookie = "Authorization=" + token
document.location.pathname = "/"
case Failure(e: dom.ext.AjaxException) =>
Utils.addAlert("danger", JSON.parse(e.xhr.responseText).selectDynamic("message").asInstanceOf[String])
}
}
}
示例8: Demo1
//设置package包名称以及导入依赖的类
package demo
import java.lang.Math._
import org.scalajs.dom
import org.scalajs.dom.{CanvasRenderingContext2D, html}
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
@JSExportTopLevel("Demo1")
object Demo1 {
@JSExport
def main(canvas: html.Canvas): Unit = {
val draw: CanvasRenderingContext2D = canvas.getContext("2d").asInstanceOf[dom.CanvasRenderingContext2D]
val (h, w) = (canvas.height, canvas.width)
var x = 0.0
var xx = x
var inc = 1
val graphs = Seq[(String, Double => Double)](
("red", sin),
("green", x => 2 - abs(x % 8 - 4)),
("blue", x => 3 * pow(sin(x / 12), 2) * sin(x))
).zipWithIndex
dom.window.setInterval(() => {
xx = xx + inc
x = (x + 1) % w
if (x == 0) {
draw.clearRect(0, 0, w, h)
inc = -inc
}
else for (((color, func), i) <- graphs) {
val y = func(xx/w * 75) * h/40 + h/graphs.size * (i+0.5)
draw.fillStyle = color
draw.fillRect(xx, y, 1, 1)
}
}, 10)
}
}
示例9: Demo2
//设置package包名称以及导入依赖的类
package demo
import java.lang.Math._
import org.scalajs.dom
import org.scalajs.dom.html
import paperjs.Basic.Point
import paperjs.Paper
import paperjs.Paths.Path
import paperjs.Styling.Color
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
@JSExportTopLevel("Demo2")
object Demo2 {
@JSExport
def main(canvas: html.Canvas): Unit = {
Paper.setup(canvas)
val (h, w) = (canvas.height, canvas.width)
var x = 0.0
var xx = x
var inc = 1
val graphs = Seq[(String, Double => Double, Path)](
("red", sin, new Path()),
("green", x => 2 - abs(x % 8 - 4), new Path()),
("blue", x => 3 * pow(sin(x / 12), 2) * sin(x), new Path())
).zipWithIndex
dom.window.setInterval(() => {
xx = xx + inc
x = (x + 1) % w
if (x == 0) {
for (((color, func, path), i) <- graphs) {
path.removeSegments(0, path.segments.length)
}
inc = -inc
}
else for (((color, func, path), i) <- graphs) {
val y = func(xx / w * 75) * h / 40 + h / graphs.size * (i + 0.5)
path.strokeColor = Color(color)
path.add(new Point(xx, y))
path.smooth()
}
}, 10)
}
}
示例10: VariableStorage
//设置package包名称以及导入依赖的类
package globalvariables
import sharednodejsapis.IPCRenderer
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}
/**
* VariableStorage allows to contact the BrowserWindow responsible for storing variables, in order to passe them from
* pages to pages.
*/
@JSExportTopLevel("VariableStorage")
object VariableStorage {
/**
* Stores the value under the key identifier for the webContents.
* @param key key identifier
* @param value value to store
*/
@JSExport("storeValue")
def storeValue(key: String, value: Any): Unit =
IPCRenderer.sendSync("store-value", key, value)
/**
* Returns a value previously stored under the key identifier.
* @param key key identifier under which the value was stored
* @return the value previously stored, or null if was not stored before.
*/
@JSExport("retrieveValue")
def retrieveValue(key: String): Any =
IPCRenderer.sendSync("retrieve-value", key)
/**
* Removes the value stored under the key identifier.
*/
@JSExport("unStoreValue")
def unStoreValue(key: String): Unit =
IPCRenderer.sendSync("unStore-value", key)
/**
* Stores the value for global usage under the key identifier.
*/
@JSExport("storeGlobalValue")
def storeGlobalValue(key: String, value: Any): Unit =
IPCRenderer.sendSync("store-global-value", key, value)
/**
* Retrieve a previously set global variable under the key identifier.
*/
@JSExport("retrieveGlobalValue")
def retrieveGlobalValue(key: String): Any = IPCRenderer.sendSync("retrieve-global-value", key)
/**
* Removes the global value stored under the key identifier.
*/
@JSExport("unStore-global-value")
def unStoreGlobalValue(key: String): Unit = IPCRenderer.sendSync("unStore-global-value", key)
}