Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Oct 17 02:41
    scala-steward opened #296
  • Oct 06 19:15
    scala-steward opened #295
  • Oct 04 09:58
    romansky commented #294
  • Oct 04 09:02
    Atry closed #294
  • Oct 04 09:02
    Atry commented #294
  • Oct 01 15:27

    Atry on master

    Update the link (compare)

  • Oct 01 15:17
    romansky opened #294
  • Sep 29 23:57
    scala-steward opened #293
  • Sep 18 21:04
    scala-steward opened #292
  • Sep 14 19:28
    scala-steward opened #291
  • Sep 08 17:57
    scala-steward opened #290
  • Aug 31 04:42
    scala-steward opened #289
  • Aug 11 03:17
    scala-steward opened #288
  • Aug 07 06:53
    scala-steward opened #287
  • Jul 27 16:34
    scala-steward opened #286
  • Jul 20 19:58
    scala-steward opened #285
  • Jul 11 00:24
    scala-steward opened #284
  • Jun 30 21:04
    scala-steward opened #281
  • Jun 29 15:04
    scala-steward opened #280
  • Jun 28 01:13
    scala-steward opened #279
Yang, Bo
@Atry
I suppose you can easily port Binding.scala 10.x to SJS1, without Scala 2.13 support.
Dylan Arnold
@DylanArnold
Scalafmt 2.6.0 has just been tagged, fixing scalameta/scalafmt#1882 to support formatting Scala embedded within XML. See https://scalameta.org/scalafmt/docs/configuration.html#xml for details to enable if you would like to format your Binding.scala code.
Nabodit Paudyal
@NaBandit

Hi @Atry, great stuff here, really like the library. Im struggling however with it a little however. Trying to follow the example here: https://github.com/GlasslabGames/html.scala/blob/71ec2406d51c1b2fe92a75cffaf0adc5f074bd93/html/src/main/scala/org/lrng/binding/html.scala#L926

The ElementBuilder and TextBuilder are private, is there an implicit I am missing?

Yang, Bo
@Atry
They are not private
Philipp Dörfler
@phdoerfler
I'm migrating from @dom to @html. I had this code on ScalaFiddle before, where it worked great but only had access to an old version of Binding.scala, and thus only @dom.
Now with the latest and greatest Binding.scala and @html I am getting this annoying error:
case class Row(input: Input, result: Element, name: String, description: String, limits: Limits, precision: Double) {
  val data = Var(0d)

  def adjustedValue = input.value.toDouble / precision

  @html def update() = {
    data.value = adjustedValue // <- compile error
    result.innerHTML = precision match {
      case 1 => adjustedValue.toString
      case 10 => f"$adjustedValue%.1f"
    }
  }
}
28:7: reference to data is ambiguous;
it is both defined in class Row and imported subsequently by 
import _root_.org.lrng.binding.html.autoImports.{$bang$eq=>_, $hash$hash=>_, $eq$eq=>_, eq=>_, equals=>_, getClass=>_, hashCode=>_, ne=>_, notify=>_, notifyAll=>_, synchronized=>_, toString=>_, wait=>_, _}
      data.value = adjustedValue
      ^
one error found
There's more stuff in that case class, but I removed most of the non relevant code
To me this looks like a bug. I see no reason why data should be ambiguous.
Yang, Bo
@Atry
Try this.data
Philipp Dörfler
@phdoerfler
@Atry that works, thanks!
should I file a bug report?
and if so: Where? the html project?
Philipp Dörfler
@phdoerfler
@html def wire() = {
  val d = this.data.bind // compile error
  result.innerHTML = precision match {
    case 1 => d.toString
    case 10 => f"$d%.1f"
  }
}
now results in:
`each` instructions must not appear outside monadic blocks.
  Note that the `each` instructions may be renamed for different domains.
  The renamed instruction name may be `bind`, `!`, `await`, `gen`, etc.)
      val d = this.data.bind
                        ^
one error found
Philipp Dörfler
@phdoerfler
Ah, right, it now needs to be within an xml tag
Philipp Dörfler
@phdoerfler
I was able to use @dom with http://www.lihaoyi.com/scalatags/ quite easily. But how do I do the same with @html? Simply replacing @dom with @html often times gives me the aforementioned "each instruction must not appear outside monadic blocks" error.
I understand that in theory @html is superior to @dom but it's a lot harder to use, I have to say.
which is unfortunate
Philipp Dörfler
@phdoerfler
Also there's the question of how @html is gonna translate to dotty
Philipp Dörfler
@phdoerfler
Is there any chance @html will become as composable as @dom?
Philipp Dörfler
@phdoerfler
I hope I don't come across as just complaining! Binding.scala is great and I'm glad it's there!
Philipp Dörfler
@phdoerfler
I just realised that a lot of my problems are solved by just putting stuff in Binding { … } and using that
Is it possible to add this to the each instructions must not appear outside monadic blocks. error message?
Philipp Dörfler
@phdoerfler
with this it all makes a lot more sense now :)
Philipp Dörfler
@phdoerfler
@Atry svg! I found this ancient issue: ThoughtWorksInc/Binding.scala#4 But this was in @domtimes, how do I do this in the new @htmlworld order? I am getting this error:
value svg is not a member of object org.lrng.binding.ElementFactories
did you mean img, sub, or sup?
    <svg height="100" width="100">
     ^
Philipp Dörfler
@phdoerfler
Can we use something like https://github.com/wooorm/svg-tag-names to generate code for SVG for the ElementFactories?
Nabodit Paudyal
@NaBandit
@phdoerfler I think you need to implement the SVG side of it for some charts and svg animations. I'm trying to do it this way but seems like I cannot access ElementBuilder
constructor ElementBuilder in class ElementBuilder cannot be accessed in object svg from object svg in object elements
object Test {

  implicit final class SVGUriOps(uriFactory: html.autoImports.xml.uris.type) {
    @inline def `http://www.w3.org/2000/svg` = svg
  }

  object svg {
    @inline def noPrefix[Uri](uri: Uri) = uri

    object uris {
      @inline def `http://www.w3.org/2000/svg` = this
    }

    object elements {

      object svg extends Curried {
        @inline def applyBegin = new NodeBinding.Constant.ElementBuilder(document.createElementNS("http://www.w3.org/2000/svg", "svg").asInstanceOf[SVGSVGElement])
      }

      object rect extends Curried {
        @inline def applyBegin = new NodeBinding.Constant.ElementBuilder(document.createElementNS("http://www.w3.org/2000/svg", "rect").asInstanceOf[SVGRectElement])

        @inline def interpolation = Binding

        object attributes {
          def x(value: String): AttributeBuilder.Untyped = {
            new html.NodeBinding.Constant.AttributeBuilder.Untyped(_.setAttributeNS(null, "x", value))
          }

          def y(value: String): AttributeBuilder.Untyped = {
            new html.NodeBinding.Constant.AttributeBuilder.Untyped(_.setAttributeNS(null, "y", value))
          }

          def height(value: String): AttributeBuilder.Untyped = {
            new html.NodeBinding.Constant.AttributeBuilder.Untyped(_.setAttributeNS(null, "height", value))
          }

          def width(value: String): AttributeBuilder.Untyped = {
            new html.NodeBinding.Constant.AttributeBuilder.Untyped(_.setAttributeNS(null, "width", value))
          }

          def fill(value: String): AttributeBuilder.Untyped = {
            new html.NodeBinding.Constant.AttributeBuilder.Untyped(_.setAttributeNS(null, "width", value))
          }
        }

      }

    }

    object attributes {
      def x(value: String) = {
        new html.NodeBinding.Constant.AttributeBuilder.Untyped(_.setAttribute("x", value))
      }

      def y(value: String) = {
        new html.NodeBinding.Constant.AttributeBuilder.Untyped(_.setAttribute("y", value))
      }
    }

    @inline def interpolation = Binding
  }

  val candles = Vars.empty[Candle]
  def consume(candle: Candle) = ???

  val candle = Candle()
  def consume(): Unit = {
    candle.colour.value = if (candle.colour.value == "red") "green" else "red"
  }
  @html
  val mySvg1 = <svg xmlns="http://www.w3.org/2000/svg" data:x="500" data:y="500">{<rect data:x="50" data:y="50" data:height="50" data:width="50" data:fill={candle.colour.bind}></rect>}</svg>
}
Nabodit Paudyal
@NaBandit

it it still possible however, to do something like this, to get a working applyBegin method:

object SVGSVGFactory extends ElementFactory[SVGSVGElement] {
    override protected def tagName: String = "svg"
  }

Whose applyBegin method is

@inline def applyBegin = new NodeBinding.Constant.ElementBuilder(document.createElement(tagName).asInstanceOf[E])

And the applybegin in the svg becomes

object svg extends Curried {
        @inline def applyBegin = SVGSVGFactory.applyBegin
      }

But this is not good enough for my purposes as createElementNS is the desired method instead of createElement
@Atry any thoughts? Or am I missing the mark completely here

Philipp Dörfler
@phdoerfler
@NaBandit How about instead modifying the build of html.scala, adding the missing generators?
https://github.com/element-io/svg-tags/blob/master/lib/svg-tags.json has a list of the SVG tags of SVG 1.1, similar to https://whatwg.org which has a list of HTML entities etc. in json. The latter is used by the build to generate the code (ElementFactories, AttributeFactories, …) with scalameta, already
https://github.com/GlasslabGames/html.scala/blob/master/project/Generators.scala#L143 this is one example where the build fetches such a list and generates code
imho, all it's missing is the equivalent for svg, is that right @Atry?
Would you accept a PR filling that niche?
Nabodit Paudyal
@NaBandit
I need to experiment with it a little, see if I can get it to work. But yeah, I think svgs are important(common?) enough to merit their implementations
Philipp Dörfler
@phdoerfler
imho adding generators is the only way to do this
I don't care if they go into the html.scala library or a different library just for svg, but really, svg is so closely tied to html already, it makes sense
besides, it's not a lot of tags
I don't understand why it's necessary to generate code for every different tag you wanna use. I guess this makes it more typesafe? But it makes it near impossible to use custom xml tags.
Philipp Dörfler
@phdoerfler
@Atry Trying to compile html.scala, I get
[error] (html / update) sbt.librarymanagement.ResolveException: Error downloading com.thoughtworks.binding:binding_sjs1_2.11:11.9.0
[error]   Not found
[error]   Not found
[error]   not found: /Users/phi/.ivy2/local/com.thoughtworks.binding/binding_sjs1_2.11/11.9.0/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/com/thoughtworks/binding/binding_sjs1_2.11/11.9.0/binding_sjs1_2.11-11.9.0.pom
[error] Error downloading com.thoughtworks.binding:bindable_sjs1_2.11:1.1.0
[error]   Not found
[error]   Not found
[error]   not found: /Users/phi/.ivy2/local/com.thoughtworks.binding/bindable_sjs1_2.11/1.1.0/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/com/thoughtworks/binding/bindable_sjs1_2.11/1.1.0/bindable_sjs1_2.11-1.1.0.pom
[error] Total time: 1 s, completed 2 Aug 2020, 11:44:28
Yang, Bo
@Atry

Would you accept a PR filling that niche?

SVG support probably should belong to a separate library. However, the SVG library might use some shared code with html.scala. Let me know if there is any blocker prevent you calling those shared code. I am happy to merge PRs for extracting shared code from html.scala.

@Atry Trying to compile html.scala, I get

[error] (html / update) sbt.librarymanagement.ResolveException: Error downloading com.thoughtworks.binding:binding_sjs1_2.11:11.9.0
[error]   Not found
[error]   Not found
[error]   not found: /Users/phi/.ivy2/local/com.thoughtworks.binding/binding_sjs1_2.11/11.9.0/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/com/thoughtworks/binding/binding_sjs1_2.11/11.9.0/binding_sjs1_2.11-11.9.0.pom
[error] Error downloading com.thoughtworks.binding:bindable_sjs1_2.11:1.1.0
[error]   Not found
[error]   Not found
[error]   not found: /Users/phi/.ivy2/local/com.thoughtworks.binding/bindable_sjs1_2.11/1.1.0/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/com/thoughtworks/binding/bindable_sjs1_2.11/1.1.0/bindable_sjs1_2.11-1.1.0.pom
[error] Total time: 1 s, completed 2 Aug 2020, 11:44:28

Could you ask these general questions on StackOverflow, please?

2 replies

should I file a bug report?

Yes, please

Iain Cardnell
@idc101
Hi, I pasted quite a lot of HTML (125 lines) into a function and after that sbt fails with OutOfMemory. I increased sbt's memory to 8g and same thing so it's not just it needed a little more memory.
Is this a known issue with Binding.scala?
Yang, Bo
@Atry
Would you mind posting the question on stackoverflow?
Iain Cardnell
@idc101
sure
sparlampe
@sparlampe
Hi all, I am trying to figure out how to work with source maps in scalajs apps. I found https://github.com/ThoughtWorksInc/sbt-scala-js-map that seems to showcase correctly functioning source maps in a scalajs app, which is at http://todomvc.com/examples/binding-scala/#/.
However, when I load the application I get the following warning in the console DevTools failed to load SourceMap: Could not load content for http://todomvc.com/examples/binding-scala/js/js-fastopt.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE. Is there a way to fix this?
Yang, Bo
@Atry
@sparlampe Thank you for pointing it out. It seems it is not configured correctly.
Joseph Hajduk
@josephhajduk
Is there a scala 3 roadmap or plan somewhere?
Roman Landenband
@romansky
@Atry any chance for help with ThoughtWorksInc/Binding.scala#294 ?
Roman Landenband
@romansky
@Atry can't find a way around https://stackoverflow.com/questions/64103296/binding-scala-how-to-get-updating-count-from-vars it looks like a type variance issue I am not able to get around, the basic all.bind will just not compile, this is a public method but I can't see anyone is using it..