本文整理汇总了Scala中scala.scalajs.js.JSApp类的典型用法代码示例。如果您正苦于以下问题:Scala JSApp类的具体用法?Scala JSApp怎么用?Scala JSApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSApp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: TorrentStreamFrontend
//设置package包名称以及导入依赖的类
package com.karasiq.torrentstream.frontend
import com.karasiq.bootstrap.BootstrapImplicits._
import com.karasiq.bootstrap.grid.GridSystem
import com.karasiq.bootstrap.icons.FontAwesome
import com.karasiq.bootstrap.navbar.{NavigationBar, NavigationTab}
import com.karasiq.torrentstream.frontend.components.TorrentManagementPanel
import org.scalajs.dom
import org.scalajs.jquery.jQuery
import rx._
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scalatags.JsDom.all._
@JSExport
object TorrentStreamFrontend extends JSApp {
private implicit val context = implicitly[Ctx.Owner]
@JSExport
override def main(): Unit = {
jQuery(() ? {
val navigationBar = NavigationBar(
NavigationTab("Torrents", "torrents", "file".fontAwesome(FontAwesome.fixedWidth), new TorrentManagementPanel)
)
val body = dom.document.body
body.appendChild(navigationBar.navbar("TorrentStream").render)
body.appendChild {
GridSystem.container(id := "main-container")(
GridSystem.mkRow(navigationBar.content)
).render
}
})
}
}
示例2: Example
//设置package包名称以及导入依赖的类
import scala.scalajs.js.JSApp
import org.scalajs.dom
import xyz.ariwaranosai.tidori.dom.DomElements._
import xyz.ariwaranosai.tidori.dom.OperatorContext
import scalatags.JsDom.all._
import xyz.ariwaranosai.tidori.dom.DomOperator._
import xyz.ariwaranosai.tidori.dom.BeatOperatorImplicit._
object Example extends JSApp {
@scala.scalajs.js.annotation.JSExport
override def main(): Unit = {
println("hello world!")
val pNode = dom.document.getElementById("broad")
val c = OperatorContext(pNode, 200)
val twitter = a(href:="https://twitter.com/ariwaranosai").render.bbs("twitter")
val blog = a(href:="http://ariwaranosai.xyz").render.bbs("blog")
val title = "????-???? ? ?? ".bb ~: htmlBR.b ~:
" ??????,???????,?????? ".bb ~: htmlBR.b ~:
" ????,?????,????".bb ~: 4.del() ~: 1.delay ~:
speed(4) ~: "???".bb ~: speed(0.25) ~: ",???? ".bb ~: htmlBR.b ~:
" ????? ????? ?????? ".bb ~: htmlBR.b ~:
" vim? ??? ???? ?3ds??? ".bb ~: htmlBR.b ~:
" ?haskell????,????Scala??,?????Python ".bb ~: htmlBR.b ~:
" C++????????,????????? ".bb ~: htmlBR.b ~:
" ????????,?????? ".bb ~: htmlBR.b ~:
" OSX Fedora Arch Win HHKB ".bb ~: htmlBR.b ~:
" ?????,??????????? ".bb ~: htmlBR.b ~:
" ??: ".bb ~: twitter ~: " ".bb ~: blog
title.run(c)
}
}
示例3: App
//设置package包名称以及导入依赖的类
package net.xylophones.frogger
import org.scalajs.dom
import org.scalajs.dom.document
import org.scalajs.dom.html.{Canvas}
import scala.scalajs.js.JSApp
import scala.scalajs.js.timers._
object App extends JSApp {
private val canvas = document.getElementById("frogger").asInstanceOf[Canvas]
val ctx = canvas.getContext("2d").asInstanceOf[dom.CanvasRenderingContext2D]
private val mediaPath = canvas.getAttribute("mediaPath")
private val soundPlayer = new SoundPlayer(mediaPath)
def main(): Unit = {
addCanvas()
val m = Layers.initialModel()
loop(model = m)
}
def loop(lastTime: Long = System.currentTimeMillis, model: Model): Unit = {
draw(model)
val interval: Long = System.currentTimeMillis() - lastTime
val desiredPause = 1000 / 25
val pause = Math.max(0, desiredPause - interval)
setTimeout(pause) {
val newModel: Model = updateModel(model)
loop(System.currentTimeMillis(), newModel)
}
}
private def updateModel(model: Model): Model = {
val newModel = ModelUpdaters.updaters.foldLeft(model) {
(updatedModel: Model, updater: ModelUpdater) => updater.updateIfApplicable(updatedModel)
}
for (s <- newModel.sounds) {soundPlayer.play(s)}
newModel.copy(sounds = Seq())
}
def draw(model: Model) = {
(model.layers.all zip model.positions).foreach { case (l, p) => l.draw(ctx, p, model) }
model.layers.frogLayer.draw(ctx, model.frogPosition, model)
}
def addCanvas(): Unit = {
canvas.width = Config.gameWidth
canvas.height = Config.gameHeight
}
}
示例4: Context
//设置package包名称以及导入依赖的类
package org.codeape.sc.frontend
import io.udash._
import io.udash.wrappers.jquery._
import org.codeape.sc.shared.MainServerREST
import org.scalajs.dom
import org.scalajs.dom.{Element, document}
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scala.util.Try
object Context {
implicit val executionContext = scalajs.concurrent.JSExecutionContext.Implicits.queue
private val routingRegistry = new RoutingRegistryDef
private val viewPresenterRegistry = new StatesToViewPresenterDef
implicit val applicationInstance = new Application[RoutingState](routingRegistry, viewPresenterRegistry, RootState)
import io.udash.rest._
val port = Try(dom.window.location.port.toInt).getOrElse(80)
val host = dom.window.location.hostname
val restServer = DefaultServerREST[MainServerREST](host, port, "/api/")
}
object Init extends JSApp with StrictLogging {
import Context._
@JSExport
override def main(): Unit = {
logger.info("StampClock started")
jQ(document).ready((_: Element) => {
val appRoot = jQ("#application").get(0)
if (appRoot.isEmpty) {
logger.error("Application root element not found! Check your index.html file!")
} else {
applicationInstance.run(appRoot.get)
}
})
}
}
示例5: Main
//设置package包名称以及导入依赖的类
package formulate
import formulate.react._
import japgolly.scalajs.react._
import japgolly.scalajs.react.vdom.prefix_<^._
import monocle._
import org.scalajs.dom
import scala.scalajs.js.JSApp
object Main extends JSApp {
val form: Form =
GroupForm((1 to 100).map(i => TextField(s"Item $i")).toList)
val Main = ReactComponentB[Unit]("FormBuilder example")
.initialState(form)
.render { proxy =>
<.table(
<.tbody(
<.tr(
<.td(FormRenderer.Default(proxy)),
<.td(FormRenderer.ReadOnly(proxy))
)
)
)
}
.build
def main(): Unit =
ReactDOM.render(Main(), dom.document.getElementById("app"))
}
示例6: ScalaJSExamples
//设置package包名称以及导入依赖的类
package com.outr.nextui.examples.browser
import com.outr.nextui.browser.ScalaJS
import com.outr.nextui.examples.Examples
import org.scalajs.dom.{Event, document, html}
import scala.scalajs.js.JSApp
object ScalaJSExamples extends JSApp {
override def main(): Unit = {
val div = document.createElement("div").asInstanceOf[html.Div]
Examples().foreach { ui =>
val a = document.createElement("a").asInstanceOf[html.Anchor]
a.href = "#"
a.addEventListener("click", {(evt: Event) =>
document.body.removeChild(div)
ScalaJS(ui)
}, true)
a.textContent = ui.name
val p = document.createElement("p").asInstanceOf[html.Paragraph]
p.appendChild(a)
div.appendChild(p)
}
document.body.appendChild(div)
}
}
示例7: TutorialApp
//设置package包名称以及导入依赖的类
package tutorial.webapp
import scala.scalajs.js.JSApp
import scala.scalajs.js
import js.DynamicImplicits._
import js.Dynamic.{global => g}
object TutorialApp extends JSApp {
val five = g.require("johnny-five")
def main(): Unit = {
five.Board().on("ready", () => {
println("Board ready")
val led = five.Led(13)
led.blink(500)
})
}
}
示例8: Init
//设置package包名称以及导入依赖的类
package com.oni.udash
import acyclic.file
import io.udash._
import io.udash.wrappers.jquery._
import org.scalajs.dom.{ Element, document }
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import scalacss.Defaults._
import scalacss.ScalatagsCss._
import scalatags.JsDom._
import com.oni.udash.styles._
import com.oni.udash.styles.OniStyles2
import com.oni.udash.styles.GlobalStyles
import com.oni.udash.styles.DemoStyles
import com.oni.udash.styles.partials.FooterStyles
import com.oni.udash.styles.partials.HeaderStyles
import org.scalajs.dom.raw.HTMLStyleElement
object Init extends JSApp with StrictLogging {
import Context._
@JSExport
override def main(): Unit = {
jQ(document).ready((_: Element) => {
val appRoot = jQ("#application").get(0)
if (appRoot.isEmpty) {
logger.error("Application root element not found! Check your index.html file!")
} else {
applicationInstance.run(appRoot.get)
jQ(GlobalStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(DemoStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(OniStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(OniStyles2.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(CsStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(CsStyles2.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(FooterStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
jQ(HeaderStyles.render[TypedTag[HTMLStyleElement]].render).insertBefore(appRoot.get)
}
})
}
}
示例9: SubstrateApp
//设置package包名称以及导入依赖的类
package diversion.substrate
import java.lang.Math._
import org.scalajs.dom
import org.scalajs.dom.CanvasRenderingContext2D
import org.scalajs.dom.html.Canvas
import scala.scalajs.js
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
object SubstrateApp extends JSApp {
@JSExport
override def main(): Unit = {}
@JSExport
def start(canvasName: String): Unit = {
val canvas = dom.document.getElementById(canvasName).asInstanceOf[Canvas]
val ctx = canvas.getContext("2d").asInstanceOf[CanvasRenderingContext2D]
def h = canvas.height
def w = canvas.width
clear(canvas)
var x = 0.0
type Graph = (String, Double => Double)
val graphs = Seq[Graph](
("red", sin),
("green", x => abs(x % 4 - 2) - 1),
("blue", x => sin(x / 12) * sin(x))
).zipWithIndex
js.timers.setInterval(20) {
x = (x + 1) % w
if (x == 0) {
clear(canvas)
}
for (((color, f), i) <- graphs) {
val offset = h / 3 * (i + 0.5)
val y = f(x / w * 75) * h / 30
ctx.fillStyle = color
ctx.fillRect(x, y + offset, 3, 3)
}
}
}
def clear(canvas: Canvas): Unit = {
canvas.width = canvas.clientWidth
canvas.height = canvas.clientHeight
}
}
示例10: Paths
//设置package包名称以及导入依赖的类
package org.pragmas.OxShow
import macrocompat.bundle
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation._
import org.scalajs.dom.raw.HTMLElement
import org.scalajs.dom
import scalatags.JsDom.all._
object Paths {
val origin = dom.window.location.origin
val public = s"${origin}/public"
val defs = s"${public}/defs"
}
object MainApp extends JSApp {
var container: HTMLElement = _
def preparePage(defJson: String): Unit = {
val ddp = new DocumentDefinitionParser(defJson)
val dp = new DocumentProducer(ddp.doc)
val dpc = div(cls:="document-producer-container").render
this.container.appendChild(dpc)
dp.pageContent(dpc)
}
@JSExport
def load(id: String, document: String) = {
this.container = dom.document.getElementById(id).asInstanceOf[HTMLElement]
preparePage(document)
}
def main() : Unit = {
}
}
示例11: TutorialApp
//设置package包名称以及导入依赖的类
package jp.ne.opt.client
import jp.ne.opt.domain.TodoStore
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
import japgolly.scalajs.react.{ReactComponentB, ReactDOM}
import japgolly.scalajs.react.vdom.prefix_<^._
import org.scalajs.dom.document
object TutorialApp extends JSApp {
def main(): Unit = {
println("helloWorld")
}
@JSExport
def count():Unit = {
countNumber +=1
println(countNumber)
}
var countNumber: Int = 1
val Hello =
ReactComponentB[String]("Hello")
.render_P(name => <.div(^.id:="hoge","Hello there ", name))
.build
ReactDOM.render(Hello("hohohohoho"), document.getElementById("content"))
}
示例12: initialize
//设置package包名称以及导入依赖的类
package scalatags.hokko
import hokko.core.{DBehavior, Engine}
import org.scalajs.dom
import scala.scalajs.js.JSApp
trait HokkoDomApp extends JSApp {
lazy val htmldsl = scalatags.Hokko.all
lazy val extraHtml = scalatags.Hokko.tags2
type Html = htmldsl.Tag
def initialize(): dom.Element = {
val engine = Engine.compile(ui, ui.changes)
val domPatcher = new DomPatcher(ui.init.render(engine))
engine.subscribeForPulses { pulses =>
pulses(ui.changes).foreach { tag =>
val newVDom = tag.render(engine)
domPatcher.applyNewState(newVDom)
}
}
domPatcher.renderedElement
}
def main(): Unit = {
println("Starting App")
def start(): Unit = {
val element = this.initialize()
this.container.appendChild(element)
()
}
if (dom.document.readyState != "loading") start()
else
dom.document
.addEventListener("DOMContentLoaded", (_: dom.Event) => start())
}
def container: dom.Element = dom.document.body
def ui: DBehavior[Html]
}
示例13: App
//设置package包名称以及导入依赖的类
package app
import scala.scalajs.js.annotation.JSExport
import org.scalajs.dom
import japgolly.scalajs.react.ReactDOM
import scala.scalajs.js.JSApp
import japgolly.scalajs.react.ReactComponentB
import css.StyleStore.MyStyles
import scalacss.Defaults._
import scalacss.ScalaCssReact._
import scalacss.internal.mutable.GlobalRegistry
@JSExport
object App extends JSApp {
private val component = ReactComponentB[Unit]("App")
.render(_ => AppRouter.component())
.build
@JSExport
def main(): Unit = {
println("-----> in App AdminUser -------")
MyStyles.addToDocument()
GlobalRegistry.addToDocumentOnRegistration()
ReactDOM.render(component(), dom.document.getElementById("mainRootBody"))
}
}
示例14: App
//设置package包名称以及导入依赖的类
package chartjs
import chartjs.chart.{DataSet, Line}
import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport
object App extends JSApp {
def main(): Unit = {
chart()
}
@JSExport
def chart(): Any = {
val tsc = TimeSeriesChart("chart", Line)
tsc.appendDataSet("TTEst")
tsc.append(1, 1)
tsc.append(2, 2)
tsc.append(3, 3)
tsc.append(4, 3)
}
}
示例15: SampleApp1
//设置package包名称以及导入依赖的类
package se.ta
import scala.concurrent.duration._
import scala.scalajs.js.JSApp
import japgolly.scalajs.react._
import japgolly.scalajs.react.vdom.prefix_<^._
import monix.execution.Scheduler.Implicits.global
import monix.reactive.Observable
import org.scalajs.dom.document
object SampleApp1 extends JSApp {
def viewTick(tick: Long) =
<.div(
<.p(s"Tick: $tick seconds")
)
val Tick =
ReactComponentB[Long]("Tick")
.render_P(tick => viewTick(tick))
.build
def main(): Unit = {
println("Starting counting 10 ticks")
Observable.interval(1 second)
.doOnNext(x => ReactDOM.render(Tick(x), document.body))
.take(10)
.dump("0")
.subscribe()
}
}