Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jun 08 17:32
    scala-steward closed #322
  • Jun 08 17:32
    scala-steward commented #322
  • Jun 08 17:32
    scala-steward opened #326
  • May 14 18:48
    scala-steward closed #324
  • May 14 18:48
    scala-steward commented #324
  • May 14 18:48
    scala-steward opened #325
  • Apr 20 21:39
    scala-steward closed #323
  • Apr 20 21:39
    scala-steward commented #323
  • Apr 20 21:39
    scala-steward opened #324
  • Apr 01 07:36
    scala-steward closed #318
  • Apr 01 07:36
    scala-steward commented #318
  • Apr 01 07:36
    scala-steward opened #323
  • Mar 31 17:33
    scala-steward closed #313
  • Mar 31 17:33
    scala-steward commented #313
  • Mar 31 17:33
    scala-steward opened #322
  • Mar 29 00:41
    vmchura commented #4
  • Mar 12 20:36
    scala-steward closed #320
  • Mar 12 20:36
    scala-steward commented #320
  • Mar 12 20:36
    scala-steward opened #321
  • Mar 11 06:16
    scala-steward opened #320
Gino Emiliozzi
@ginoemiliozzi
Hello, I'm using Binding with Scala 2.13 and I get this error:
[error] found : com.thoughtworks.binding.Binding.BindingSeq[org.scalajs.dom.Node]{def value: scala.collection.Seq[org.scalajs.dom.Node]}
[error] (which expands to) com.thoughtworks.binding.Binding.BindingSeq[org.scalajs.dom.raw.Node]{def value: scala.collection.Seq[org.scalajs.dom.raw.Node]}
[error] required: org.lrng.binding.html.NodeBindingSeq[org.scalajs.dom.raw.HTMLDivElement]
[error] (which expands to) com.thoughtworks.binding.Binding.BindingSeq[org.scalajs.dom.raw.HTMLDivElement]{def value: scala.collection.Seq[org.scalajs.dom.raw.HTMLDivElement]}
[error] <div>
[error] ^
[error] one error found
Does anyone know how to solve it? Seems like the compiler get confused with @dom library instead of @html
Yang, Bo
@Atry
@ioleo I think style: prefix is not supported in @html.
@ginoemiliozzi @html is not 100% compatible with @dom. Same code will produce different types when you switch the annotation to @html. We have to change your type accordingly.
ioleo
@ioleo
Is there a chance @dom will be upgraded to SJS 1? @Atry
I'd prefer to use it becouse it seems more feature rich and better documented (at the moment).
Yang, Bo
@Atry
Feel free to create PR to port @dom it to SJS1. I suppose it's not that hard.
But Scala 2.13 is a breaking change, and it's really difficult to port @dom to 2.13.
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?