6

I have a Vars binding statement, like so

val data: Vars[Contact] = Vars.empty[Contact]

I'm trying to show the number of elements like so:

<div>{data.all.bind.size}</div>

But this produces a complication error

type mismatch;
[error]  found   : com.thoughtworks.binding.Binding[App.this.data.All[App.this.Contact]]
[error]     (which expands to)  com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_ <: App.this.Contact]]
[error]  required: com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_$6]] where type _$6 <: App.this.Contact
[error]         {this.data.all.bind.size}</div>

How to make this work?

Update

trying to use String as type for Vars binding, same outcome

type mismatch;
[error]  found   : com.thoughtworks.binding.Binding[App.this.data.All[String]]
[error]     (which expands to)  com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_ <: String]]
[error]  required: com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_$6]] where type _$6 <: String
[error]         {this.data.all.bind.size}</div>

Note that i'm using Scala.js 1.2, Scala 2.13.3 and libraryDependencies += "org.lrng.binding" %%% "html" % "latest.release" unfortunately, can't provide scalafiddle since it doesn't support Scala 2.13, instead I created a replica project here- https://www.dropbox.com/s/i9dpsa9pz0lejtj/bindingreplica.tar.gz?dl=0

Roman
  • 1,880
  • 1
  • 13
  • 12
  • Could you provide the `Contact` description? Or please simplify the example with replacing `Contact` to `String` and check the result. I checked `Vars.all.bind.size` binding and more appropriate `Vars.length.bind` and both are worked (please, see here https://scalafiddle.io/sf/IL27nGa/1). – lmars Sep 29 '20 at 04:22
  • No, same result ``` type mismatch; [error] found : com.thoughtworks.binding.Binding[App.this.data.All[String]] [error] (which expands to) com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_ <: String]] [error] required: com.thoughtworks.binding.Binding[scala.collection.mutable.Buffer[_$6]] where type _$6 <: String [error] {this.data.all.bind.size} ``` Note that i'm using Scala.js 1.2, scala 2.13.3 and `libraryDependencies += "org.lrng.binding" %%% "html" % "latest.release"` unfortunately, can't use scalafiddle since it doesn't support Scala 2.13 – Roman Sep 29 '20 at 07:23
  • 1
    The typing issue in `Vars.all.bind` is now fixed in https://github.com/ThoughtWorksInc/Binding.scala/pull/302 – Yang Bo Dec 31 '20 at 23:50

1 Answers1

1

You can use length for this.

<div>{data.length.bind.toString}</div>
lmars
  • 302
  • 1
  • 6
  • This fails in a different way- [error] .../src/main/scala/jstextplayground/app/App.scala:53:27: could not find implicit value for parameter bindableSeq: com.thoughtworks.binding.bindable.BindableSeq.Lt[Int,org.scalajs.dom.Node] (Could not find an instance of BindableSeq for Int) [error] {this.data.length.bind} [error] ^ [error] one error found [error] (jstestgroundJS / Compile / compileIncremental) Compilation failed [error] Total time: 7 s, completed 17 Oct 2020, 16:59:26 – Roman Oct 17 '20 at 14:00
  • I guess I need the basic "all.bind" to work, but this fails to compile.. – Roman Oct 17 '20 at 14:01
  • Please, add `toString` after `this.data.length.bind`. – lmars Oct 18 '20 at 16:20
  • I attached a sample project in my question, you can reproduce the compilation issue there – Roman Oct 18 '20 at 19:55
  • I have already downloaded your sample project. If you replace `this.data.all.bind.size` with `this.data.length.bind.toString` in your sample project, it compiles without errors. Please check my answer carefully. – lmars Oct 19 '20 at 06:06
  • You are correct.. I thought I used that in my test examples as well – Roman Oct 19 '20 at 07:37