scala.scalajs.js.annotation.JSName Scala Examples
The following examples show how to use scala.scalajs.js.annotation.JSName.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: package.scala From gbf-raidfinder with MIT License | 5 votes |
package com.momentjs import scala.scalajs.js import scala.scalajs.js.annotation.JSName @js.native @JSName("moment") object Moment extends js.Object { def apply(millis: Double): Date = js.native def locale(localeName: String): Unit = js.native def defineLocale(localeName: String, settings: js.Dictionary[js.Any]): Unit = js.native } @js.native trait Date extends js.Object { def fromNow(): String = js.native def fromNow(withoutSuffix: Boolean): String = js.native def from(millis: Double, withoutSuffix: Boolean): String = js.native def format(stringFormat: String): String = js.native }
Example 2
Source File: RxPromise.scala From scalajs-rxjs with MIT License | 5 votes |
// Project: scalajs-rxjs // Module: RxPromise // Description: Provides an extension of js.Promise with simplified event handling // Copyright (c) 2016. Distributed under the MIT License (see included LICENSE file). package rxjs import scala.scalajs.js import scala.scalajs.js.annotation.{JSGlobal, JSName} import scala.language.implicitConversions @js.native trait RxPromise[T] extends js.Promise[T] { @JSName("then") def andThen[R](onFulfilled: js.Function1[T,R]): RxPromise[R] = js.native @JSName("then") def andThen[R](onFulfilled: js.Function1[T,R], onRejected: js.UndefOr[js.Function1[js.Any,R]]): RxPromise[R] = js.native @JSName("catch") def orCatch(onError: js.Function1[js.Any,_]): RxPromise[T] = js.native } object RxPromise { @inline implicit def toObservable[T](p: RxPromise[T]): Observable[T] = Observable.fromPromise(p) type ResolveFun[T] = Function1[T,js.Promise[T]] type RejectFun = Function1[Any,js.Promise[Nothing]] @JSGlobal("Promise") @js.native private class Impl[T](executor: js.Function2[js.Function1[T,Unit],js.Function1[Any,Unit],Any]) extends js.Object def apply[T](executor: Function2[js.Function1[T,Unit],js.Function1[Any,Unit],Any]): RxPromise[T] = new Impl(executor).asInstanceOf[RxPromise[T]] def resolve[T](value: T): RxPromise[T] = js.Promise.resolve[T](value).asInstanceOf[RxPromise[T]] def reject(reason: Any): RxPromise[Nothing] = js.Promise.reject(reason).asInstanceOf[RxPromise[Nothing]] implicit final class RichRxPromise[T](val p: RxPromise[T]) extends AnyVal { @inline def map[R](f: T=>R): RxPromise[R] = p.andThen(f) @inline @deprecated("Use map() instead","0.0.2") def onFulfilled[R](f: T=>R): RxPromise[R] = p.andThen(f) @inline def onError(f: js.Any=>_): RxPromise[T] = p.orCatch(f) } }
Example 3
Source File: Promise.scala From scalajs-rxjs with MIT License | 5 votes |
// Project: scalajs-rxjs // Module: // Description: Façade trait for Promises // Copyright (c) 2016. Distributed under the MIT License (see included LICENSE file). package rxjs.core import scala.scalajs.js import scala.scalajs.js.annotation.{JSGlobal, JSName} @js.native @JSGlobal("Promise") class IPromise[T](f: js.Function2[js.Function1[T,Unit],js.Function1[T,Unit],_]) extends js.Object { @JSName("then") def andThen[U](onFulfilled: js.Function1[T,U], onRejected: js.Function1[js.Any,_]): IPromise[U] = js.native } object IPromise { implicit class RichIPromise[T](val p: IPromise[T]) extends AnyVal { @inline final def andThen[U](onFulfilled: T=>U, onRejected: js.Any=>_): IPromise[U] = p.andThen[U]( onFulfilled:js.Function1[T,U], onRejected: js.Function1[js.Any,_] ) @inline final def onSuccess[U](f: T=>U): IPromise[U] = p.andThen[U](f,null) } // def apply[T](resolve: =>T): IPromise[T] = new IPromise[T]((resolve:js.Function1[T,Unit],reject:js)) } @js.native @JSGlobal("Promise") object Promise extends js.Object { def resolve[T](value: T): IPromise[T] = js.native def reject[T](value: T): IPromise[T] = js.native }
Example 4
Source File: ReactRouterRedux.scala From scalajs-reactjs with MIT License | 5 votes |
package io.github.shogowada.scalajs.reactjs.router.redux import io.github.shogowada.scalajs.history.History import io.github.shogowada.scalajs.reactjs.VirtualDOM.VirtualDOMElements import io.github.shogowada.scalajs.reactjs.classes.ReactClass import io.github.shogowada.scalajs.reactjs.redux.Redux.{Middleware, NativeMiddleware, Reducer} import io.github.shogowada.scalajs.reactjs.redux.{NativeAction, ReduxInternal} import scala.scalajs.js import scala.scalajs.js.annotation.{JSImport, JSName} @js.native @JSImport("react-router-redux", JSImport.Namespace) object ReactRouterReduxAction extends js.Object { @JSName("push") def Push(path: String): NativeAction = js.native @JSName("replace") def Replace(path: String): NativeAction = js.native @JSName("go") def Go(delta: Int): NativeAction = js.native @JSName("goBack") def GoBack(): NativeAction = js.native @JSName("goForward") def GoForward(): NativeAction = js.native } object ReactRouterRedux { implicit class RouterReduxVirtualDOMElements(elements: VirtualDOMElements) { lazy val ConnectedRouter = elements(NativeReactRouterRedux.ConnectedRouter) } val routerReducer: Reducer[js.Object] = (state: Option[_], action: Any) => { val nativeState: js.Object = state.map(_.asInstanceOf[js.Object]).getOrElse(js.Object()) val nativeAction = ReduxInternal.actionToNative(action) NativeReactRouterRedux.routerReducer(nativeState, nativeAction) } def routerMiddleware[State](history: History): Middleware[State] = ReduxInternal.middlewareFromNative( NativeReactRouterRedux.routerMiddleware(history) ) } @js.native @JSImport("react-router-redux", JSImport.Namespace) object NativeReactRouterRedux extends js.Object { val ConnectedRouter: ReactClass = js.native def routerReducer(routerState: js.Object, action: NativeAction): js.Object = js.native def routerMiddleware(history: History): NativeMiddleware = js.native }
Example 5
Source File: Validator.scala From ProductWebUI with Apache License 2.0 | 5 votes |
package client.components import org.querki.jquery.JQuery import org.querki.jsext.{JSOptionBuilder, OptMap} import scala.scalajs.js import scala.scalajs.js.annotation.JSName import org.querki.jsext._ import scala.language.implicitConversions import scala.scalajs.js.Any /** * Created by bhagyashree.b on 2016-06-16. */ object Validator { @js.native trait ValidatorJQuery extends js.Object { def validator(options: ValidatorOptions):Any = js.native // def popover(options: PopoverOptions):Any = js.native } @js.native trait ValidatorOptions extends js.Object class ValidatorOptionBuilder(val dict:OptMap) extends JSOptionBuilder[ValidatorOptions, ValidatorOptionBuilder](new ValidatorOptionBuilder(_)) { def html(v:Boolean) = jsOpt("html", v) def validate() = jsOpt("",Any) } object ValidatorOptions extends ValidatorOptionBuilder(noOpts) implicit def jq2validator(jq: JQuery): ValidatorJQuery = jq.asInstanceOf[ValidatorJQuery] // @JSName("Validator") // def validate():Any = js.native }
Example 6
Source File: Chart.scala From ProductWebUI with Apache License 2.0 | 5 votes |
package client.components import japgolly.scalajs.react.vdom.prefix_<^._ import japgolly.scalajs.react.{ Callback, BackendScope, ReactComponentB } import org.scalajs.dom.raw.HTMLCanvasElement import scala.scalajs.js import scala.scalajs.js.JSConverters._ import scala.scalajs.js.annotation.JSName @js.native trait ChartDataset extends js.Object { def label: String = js.native def fillColor: String = js.native def strokeColor: String = js.native def data: js.Array[Double] = js.native } //@js.native object ChartDataset { def apply(data: Seq[Double], label: String, fillColor: String = "#005C99", strokeColor: String = "#000"): ChartDataset = { js.Dynamic.literal( data = data.toJSArray, label = label, fillColor = fillColor, strokeColor = strokeColor ).asInstanceOf[ChartDataset] } } @js.native trait ChartData extends js.Object { def labels: js.Array[String] = js.native def datasets: js.Array[ChartDataset] = js.native } object ChartData { def apply(labels: Seq[String], datasets: Seq[ChartDataset]): ChartData = { js.Dynamic.literal( labels = labels.toJSArray, datasets = datasets.toJSArray ).asInstanceOf[ChartData] } } // define a class to access the Chart.js component @js.native @JSName("Chart") class JSChart(ctx: js.Dynamic) extends js.Object { // create different kinds of charts def Line(data: ChartData): js.Dynamic = js.native def Bar(data: ChartData): js.Dynamic = js.native def Pie(data: ChartData): js.Dynamic = js.native } object Chart { // avaiable chart styles sealed trait ChartStyle case object LineChart extends ChartStyle case object BarChart extends ChartStyle case object PieChart extends ChartStyle case class ChartProps(name: String, style: ChartStyle, data: ChartData, width: String = "400px", height: String = "200px") class Backend(t: BackendScope[ChartProps, _]) val Chart = ReactComponentB[ChartProps]("Chart") .render_P((P) => { <.canvas(^.width := P.width, ^.height := P.height) }).componentDidMount(scope => Callback { // access context of the canvas val ctx = scope.getDOMNode().asInstanceOf[HTMLCanvasElement].getContext("2d") // create the actual chart using the 3rd party component scope.props.style match { case LineChart => new JSChart(ctx).Line(scope.props.data) case BarChart => new JSChart(ctx).Bar(scope.props.data) case PieChart => new JSChart(ctx).Pie(scope.props.data) case _ => throw new IllegalArgumentException } }).build def apply(props: ChartProps) = Chart(props) }
Example 7
Source File: Chart.scala From ProductWebUI with Apache License 2.0 | 5 votes |
package synereo.client.components import japgolly.scalajs.react.vdom.prefix_<^._ import japgolly.scalajs.react.{ BackendScope, Callback, ReactComponentB } import org.scalajs.dom.raw.HTMLCanvasElement import scala.scalajs.js import scala.scalajs.js.JSConverters._ import scala.scalajs.js.annotation.JSName @js.native trait ChartDataset extends js.Object { def label: String = js.native def fillColor: String = js.native def strokeColor: String = js.native def data: js.Array[Double] = js.native } object ChartDataset { def apply(data: Seq[Double], label: String, fillColor: String = "#005C99", strokeColor: String = "#000"): ChartDataset = { js.Dynamic.literal( data = data.toJSArray, label = label, fillColor = fillColor, strokeColor = strokeColor ).asInstanceOf[ChartDataset] } } @js.native trait ChartData extends js.Object { def labels: js.Array[String] = js.native def datasets: js.Array[ChartDataset] = js.native } object ChartData { def apply(labels: Seq[String], datasets: Seq[ChartDataset]): ChartData = { js.Dynamic.literal( labels = labels.toJSArray, datasets = datasets.toJSArray ).asInstanceOf[ChartData] } } // define a class to access the Chart.js component @js.native @JSName("Chart") class JSChart(ctx: js.Dynamic) extends js.Object { // create different kinds of charts def Line(data: ChartData): js.Dynamic = js.native def Bar(data: ChartData): js.Dynamic = js.native def Pie(data: ChartData): js.Dynamic = js.native } object Chart { // avaiable chart styles sealed trait ChartStyle case object LineChart extends ChartStyle case object BarChart extends ChartStyle case object PieChart extends ChartStyle case class ChartProps(name: String, style: ChartStyle, data: ChartData, width: Int = 400, height: Int = 200) class Backend(t: BackendScope[ChartProps, _]) val Chart = ReactComponentB[ChartProps]("Chart") .render_P((P) => { <.canvas(^.width := P.width, ^.height := P.height) }).componentDidMount(scope => Callback { // access context of the canvas val ctx = scope.getDOMNode().asInstanceOf[HTMLCanvasElement].getContext("2d") // create the actual chart using the 3rd party component scope.props.style match { case LineChart => new JSChart(ctx).Line(scope.props.data) case BarChart => new JSChart(ctx).Bar(scope.props.data) case PieChart => new JSChart(ctx).Pie(scope.props.data) case _ => throw new IllegalArgumentException } }).build def apply(props: ChartProps) = Chart(props) }
Example 8
Source File: BooApp.scala From boopickle with Apache License 2.0 | 5 votes |
package boopickle.perftests import boopickle.BufferPool import org.scalajs.dom import org.scalajs.dom.html import scala.scalajs.js import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel, JSGlobal, JSName} import scala.scalajs.js.typedarray.Uint8Array import scalatags.JsDom.all._ @JSGlobal("Zlib.Gzip") @js.native class Gzip(data: js.Array[Byte]) extends js.Object { def compress(): Uint8Array = js.native } @JSExportTopLevel("BooApp") object BooApp { import scala.scalajs.js.JSConverters._ def runTests(resultsDiv: html.Div) = { val resView = pre.render resultsDiv.innerHTML = "" resultsDiv.appendChild(div(cls := "bold", s"Running ${Tests.suites.size} tests").render) resultsDiv.appendChild(resView) def runNext(suites: Seq[PerfTestSuite]): Unit = { val suite = suites.head val header = s"${1 + Tests.suites.size - suites.size}/${Tests.suites.size} : ${suite.name}" resView.innerHTML = resView.innerHTML + header + "\n" resView.innerHTML = resView.innerHTML + "=" * header.length + "\n" resView.innerHTML = resView.innerHTML + f"${"Library"}%-10s ${"ops/s"}%-10s ${"%"}%-10s ${"size"}%-10s ${"%"}%-10s ${"size.gz"}%-10s ${"%"}%-10s" + "\n" val tester = new PerfTester(suite) val res = tester.runSuite // zip result data to see how small it gets val resSizes = res.results.map { r => val rawSize = r.data.length val gz = new Gzip(r.data.toJSArray) (r, rawSize, gz.compress().length) } val maxCount = resSizes.map(_._1.count).max val minSize = resSizes.map(_._2).min val minGZSize = resSizes.map(_._3).min resSizes.foreach { r => resView.innerHTML = resView.innerHTML + f"${r._1.name}%-10s ${r._1.count}%-10d ${f"${r._1.count * 100.0 / maxCount}%.1f%%"}%-10s ${r._2}%-10d ${f"${r._2 * 100.0 / minSize}%.0f%%"}%-10s ${r._3}%-10d ${f"${r._3 * 100.0 / minGZSize}%.0f%%"}%-10s" + "\n" } resView.innerHTML = resView.innerHTML + "\n" if (suites.tail.nonEmpty) dom.window.setTimeout(() => runNext(suites.tail), 100) else { resultsDiv.appendChild(h4("Completed!").render) } // print out buffer pool usage println(s"""BufferPool: | allocations = ${BufferPool.allocOk} | misses = ${BufferPool.allocMiss} """.stripMargin) () } dom.window.setTimeout(() => runNext(Tests.suites), 10) } @JSExport def main(): Unit = { val contentRoot = dom.document.getElementById("contentRoot") val runButton = button(cls := "waves-effect waves-light btn", i(cls := "mdi-av-play-arrow right"), "Run tests").render val results = div(cls := "row").render runButton.onclick = (e: dom.Event) => runTests(results) contentRoot.appendChild(div(cls := "row", runButton).render) contentRoot.appendChild(results) () } }
Example 9
Source File: utils.scala From scalajs-facades with MIT License | 5 votes |
package chandu0101.scalajs.facades.leaflet import org.scalajs.dom.raw.HTMLElement import scala.scalajs.js import scala.scalajs.js.annotation.JSName import scala.scalajs.js.{UndefOr, undefined} @JSName("L.Browser") object LBrowser extends js.Object { val ie : Boolean = js.native val ie6 : Boolean = js.native val ie7 : Boolean = js.native val webkit : Boolean = js.native val webkit3d : Boolean = js.native val android : Boolean = js.native val android23 : Boolean = js.native val mobile : Boolean = js.native val opera : Boolean = js.native val mobileWebkit : Boolean = js.native val mobileOpera : Boolean = js.native val touch : Boolean = js.native val msTouch : Boolean = js.native val retina : Boolean = js.native } @JSName("L.DomUtil") object LDomUtil extends js.Object { def get(id : String) : HTMLElement = js.native def getStyle(el : HTMLElement,style : String) : String = js.native def getViewportOffset(el : HTMLElement) : LPoint = js.native def create( tagName : String,className : String,container : UndefOr[HTMLElement] = undefined) : HTMLElement = js.native def disableTextSelection() : Unit = js.native def enableTextSelection() : Unit = js.native def hasCLass(el : HTMLElement,name : String) : Boolean = js.native def addClass(el : HTMLElement,name : String) : Unit = js.native def removeClass(el : HTMLElement,name : String) : Unit = js.native def setOpacity(el : HTMLElement,value : Double) : Unit = js.native def testProp(props : js.Array[String]) : js.Dynamic = js.native def getTranslateString(point : LPoint) : String = js.native def getScaleString( scale : Double,origin : LPoint) : String = js.native def setPosition(el : HTMLElement,point : LPoint,diable3D : UndefOr[Boolean] = undefined) : Unit = js.native def getPosition(el : HTMLElement) : LPoint = js.native val TRANSITION : String = js.native val TRANSFORM : String = js.native } @JSName("L.PosAnimation") class LPosAnimation extends js.Object with LEventEmitter { def run(el : HTMLElement,newPos : LPoint,duration : UndefOr[Double] = undefined,easeLinearity : UndefOr[Double] = undefined) : LPosAnimation = js.native } object LPosAnimation { def apply() = new LPosAnimation() } @JSName("L.Draggable") class LDraggable extends js.Object with LEventEmitter{ def this(el : HTMLElement , dragHandle : UndefOr[HTMLElement] = undefined) = this() def enable() : Unit = js.native def disable() : Unit = js.native } object LDraggable { def apply(el : HTMLElement , dragHandle : UndefOr[HTMLElement] = undefined) = new LDraggable(el,dragHandle) }
Example 10
Source File: TestRenderer.scala From slinky with MIT License | 5 votes |
package slinky.testrenderer import slinky.core.ReactComponentClass import slinky.core.facade.ReactElement import scala.scalajs.js import scala.scalajs.js.annotation.{JSImport, JSName} @js.native trait TestRenderer extends js.Object { def toJSON(): js.Object = js.native def toTree(): js.Object = js.native def update(element: ReactElement): Unit = js.native def unmount(): Unit = js.native def getInstance(): js.Object = js.native val root: TestInstance = js.native } @js.native @JSImport("react-test-renderer", JSImport.Default) object TestRenderer extends js.Object { def create(element: ReactElement): TestRenderer = js.native def act(callback: js.Function0[js.Any]): Unit = js.native } @js.native trait TestInstance extends js.Object { def find(test: js.Function1[TestInstance, Boolean]): TestInstance = js.native def findByType(`type`: ReactComponentClass[_]): TestInstance = js.native def findByProps(props: js.Object): TestInstance = js.native def findAll(test: js.Function1[TestInstance, Boolean]): js.Array[TestInstance] = js.native def findAllByType(`type`: ReactComponentClass[_]): js.Array[TestInstance] = js.native def findAllByProps(props: js.Object): js.Array[TestInstance] = js.native val instance: js.Object = js.native @JSName("type") val `type`: js.Object = js.native val props: js.Object = js.native val parent: TestInstance = js.native val children: js.Array[TestInstance] = js.native }
Example 11
Source File: SyntheticEvent.scala From slinky with MIT License | 5 votes |
package slinky.core import scala.scalajs.js import scala.scalajs.js.annotation.JSName @js.native trait SyntheticEvent[+TargetType, +EventType] extends js.Object { val bubbles: Boolean = js.native val cancelable: Boolean = js.native val currentTarget: TargetType = js.native val defaultPrevented: Boolean = js.native val eventPhase: Int = js.native val isTrusted: Boolean = js.native val nativeEvent: EventType = js.native def preventDefault(): Unit = js.native def isDefaultPrevented(): Boolean = js.native def stopPropagation(): Unit = js.native def isPropagationStopped(): Boolean = js.native val target: TargetType = js.native val timeStamp: Int = js.native @JSName("type") val `type`: String = js.native }