当前位置: 首页>>代码示例>>Scala>>正文


Scala JSExportTopLevel类代码示例

本文整理汇总了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
    }
  }
} 
开发者ID:suzaku-io,项目名称:suzaku,代码行数:51,代码来源:WebDemoUIEntry.scala

示例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
    }
  }
} 
开发者ID:suzaku-io,项目名称:suzaku,代码行数:49,代码来源:WebDemoAppEntry.scala

示例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
    }
  }
} 
开发者ID:suzaku-io,项目名称:suzaku,代码行数:51,代码来源:PerfUIEntry.scala

示例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
    }
  }
} 
开发者ID:suzaku-io,项目名称:suzaku,代码行数:49,代码来源:PerfAppEntry.scala

示例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
  }
} 
开发者ID:wvlet,项目名称:log,代码行数:20,代码来源:JSLogger.scala

示例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
      }
    }
  }
} 
开发者ID:erdavila,项目名称:auto-steamgifts,代码行数:51,代码来源:Main.scala

示例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])
    }
  }
} 
开发者ID:MathieuUrstein,项目名称:HEIG.SCALA.Projet,代码行数:52,代码来源:Login.scala

示例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)
  }
} 
开发者ID:lwo,项目名称:lwo.github.io,代码行数:39,代码来源:Demo1.scala

示例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)

  }
} 
开发者ID:lwo,项目名称:lwo.github.io,代码行数:47,代码来源:Demo2.scala

示例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)
} 
开发者ID:sherpal,项目名称:oh-hell-card-game,代码行数:60,代码来源:VariableStorage.scala


注:本文中的scala.scalajs.js.annotation.JSExportTopLevel类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。