Code Monkey home page Code Monkey logo

Comments (13)

JorgenG avatar JorgenG commented on May 20, 2024 2

@vodkaka Could you provide an example of this? I attempted defining it, but I am not familiar enough with Scala and Binding.scala to get it working.

EDIT: After some googling I came across this solution from reddit:
https://www.reddit.com/r/scala/comments/5se6hj/scalajs_reactive_frontend_framework/ddfhzqu/?st=iyxrpkul&sh=dc3d099d
implicit def makeIntellijHappy(x: scala.xml.Node): Binding[org.scalajs.dom.raw.Node] = ???

from binding.scala.

Atry avatar Atry commented on May 20, 2024

This issue should be reported at https://youtrack.jetbrains.com

from binding.scala.

Atry avatar Atry commented on May 20, 2024

Or you could try Scala IDE for Eclipse, which handles macros.

from binding.scala.

deontologic avatar deontologic commented on May 20, 2024

I ran into the same issue. I investigated writing a plugin to support macro highlighting, but I'm unsure of how to change the return type of annotated vals and defs.

I submitted a question to the IDEA Scala forum here with more details.

from binding.scala.

joseraya avatar joseraya commented on May 20, 2024

I am aware that the problem with highlighting is IntelliJ's but my question was about the possibility of using the library without the macro. Anyway, thank you very much for answering.

from binding.scala.

deontologic avatar deontologic commented on May 20, 2024

Scala's xml library is pretty weird. I doubt it would be possible to replace the macro by defining an implicit conversion from xml.Element to Binding[ ], but perhaps @Atry has some insight on the matter.

from binding.scala.

Atry avatar Atry commented on May 20, 2024

Binding.scala changes types of XML literals via macros. IntelliJ IDEA seems using its own typer, which does not fully understand macros and other complex Scala syntax, even for those code that does not involve macros.

I have many Scala files that do not use macros. They are still red marked by IntelliJ IDEA.

from binding.scala.

deontologic avatar deontologic commented on May 20, 2024

@joseraya Thought a bit more about it, and you can avoid having to use the @dom annotation.

Replace xml literals with scalatags's JSDom.

For example:

import scalatags.JsDom.all._

  def clicker(i: Var[Int]) = Binding[Node](
    div(
      button(onclick := {() => i := i.get + 1})("click me"),
      p("num times clicked: " + {i.bind.toString}),
      tag("test-tag")("this is a test")
    ).render
  )

  def app = Binding[Node]{
    val i = Var(0)
    div({clicker(i).bind}).render
  }

  def main(): Unit = {
    scalajs.dom.render(document.body, app)
  }

The only downside (upside? ;) ) is that you lose xml literals

from binding.scala.

Atry avatar Atry commented on May 20, 2024

The entire app is recreated whenever i changes if you don't use XML literals.

from binding.scala.

deontologic avatar deontologic commented on May 20, 2024

Yeah, just realized this :(

from binding.scala.

Atry avatar Atry commented on May 20, 2024

XHTML literals in @dom methods create very sophisticated ScalaTags code able to partially data-bind on each element and element.

I bet you never want to hard-code the code.

from binding.scala.

vodkaka avatar vodkaka commented on May 20, 2024

@deontologic @joseraya
there is a trick for you, define an implicit conversion (Node -> Binding[Node])

the complier won't do the implicit conversion, it knows what happen
but intellij will be tricked, so all type is right

from binding.scala.

ritschwumm avatar ritschwumm commented on May 20, 2024

@vodkaka lol, nice

from binding.scala.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.