scala.js

Binding.scala: Strategy to avoid too many dom-tree updates

[亡魂溺海] 提交于 2019-12-01 11:17:10
问题 In my project scala-adapters I display log entries that are sent over a websocket. As I have no control on how many entries are sent, I am looking for a strategy to avoid that the screen freezes. I created a ScalaFiddle to simulate that: https://scalafiddle.io/sf/kzr28tq This function with these parameters works perfectly: setInterval(1000) { // note the absence of () => entries.value += (0 to 100).map(_.toString).mkString("") } If the interval gets smaller and the String longer - the screen

How to embed javascript code directly in scala.js?

北慕城南 提交于 2019-11-30 12:36:22
When I use scala.js to write scala code to generate javascript, I found it difficult sometimes to wrap the 3rd-party javascript code into scala objects. Is there anyway to embed some javascript code directly? e.g. as strings? No, there isn't, on purpose. How would identifiers in the "embedded" JavaScript code bind to identifiers in the surrounding Scala.js code, for example? That would never make any sense. The ugly workaround: js.eval You can "embed" JavaScript code as a parameter to the js.eval function, obviously. import scala.scalajs.js def foo(x: Int): Unit = js.eval("console.error('hello

How do I create “options objects” in Scala.Js?

做~自己de王妃 提交于 2019-11-28 10:04:30
In idiomatic JavaScript it's common to have a function accept an "options object" as the last parameter. This is where you'd usually put all the option/seldom-used parameters, e.g. jQuery.ajax({ url: "http://www.example.com/foo", success: function() { .. } }) The current documentation for Scala.JS recommands using a Scala trait to represent the options object, but that leads to a problem when you have to create the options since you cannot pass an anonymous class into JavaScript code. How can such option objects be created from Scala code? gzm0 We recommend the following (if you chose to

What is the suggested way to instantiate a js.Object for API wrappers

大憨熊 提交于 2019-11-27 06:22:04
问题 For the following javascript API wrapper: @JSName("React") object React extends js.Object { def createClass(init: ReactClassInit): ReactClassBuilder = ??? } What is the suggested what to instantiate the following trait trait ReactClassInit extends js.Object { val render: js.ThisFunction0[js.Dynamic, js.Any] } Currently I am doing the following: val * = js.Dynamic.literal val init = *(render = new js.ThisFunction0[js.Dynamic, js.Any] { override def apply(thisArg: js.Dynamic): js.Any = { React