GithubHelp home page GithubHelp logo

Comments (5)

ramnivas avatar ramnivas commented on September 18, 2024

Can you explain a bit more? Perhaps some code snippet of what you will like to work and doesn't will help.

from scalajs-react-bridge.

lvitaly avatar lvitaly commented on September 18, 2024

Sorry that I've posted issue without additional information...
Here is examples of how to use MonocleReact extention.
This is scalajs-react snippet

ReactComponentB[ExternalVar[String]]("NameInput")
  .render{ evar =>
    def updateName = (e: ReactEventI) => evar.set(e.target.value)

    <.input(
      ^.`type` := "text",
      ^.value := evar.value,
      ^.onChange ~~> updateName
    )
  }

Here is same functionality in scalajs-react-bridge

ReactComponentB[ExternalVar[String]]("NameInput")
  .render{ evar =>
    def updateName(event: ReactEventI): Unit = evar.set(event.target.value).unsafePerformIO()

    Input(
      `type` = "text",
      labelClassName = "col-xs-2",
      wrapperClassName = "col-xs-10",
      label = _label,
      value = evar.value,
      onChange = updateName _
    )()
  }

So if I try to use MonocleReact extention in react-bridge component then I shuld call unsafe method to perform IO. In case of scalajs-react ~~> is implisite function from japgolly.scalajs.react.ScalazReact._ for perform same goal.
This is not a big deal and I undertand that it could be done by self written implicite function but I think would be great to support this kind of interoperability.
What do you think?

from scalajs-react-bridge.

lvitaly avatar lvitaly commented on September 18, 2024

Something like this should be done for improve interoperability

implicit val bridgeIO: (ReactEventI => IO[Unit]) => js.UndefOr[ReactEventI => Unit] = {
  func =>
    val _func: ReactEventI => Unit = func(_).unsafePerformIO()
    _func.asInstanceOf[js.UndefOr[ReactEventI => Unit]]
}

ReactComponentB[ExternalVar[String]]("NameInput")
  .render{ evar =>
    val updateName = (e: ReactEventI) => evar.set(e.target.value)

    Input(
      `type` = "text",
      labelClassName = "col-xs-2",
      wrapperClassName = "col-xs-10",
      label = _label,
      value = evar.value,
      onChange = updateName
    )()
  }

from scalajs-react-bridge.

ramnivas avatar ramnivas commented on September 18, 2024

I see and thanks for providing a clear example. I think the implicit conversion you provided sound like a good idea, and since that code doesn't depend on Monocle etc., adding it to scalajs-react-bridge should not be an issue (otherwise a separate module or some other dependency management technique will be needed to avoid impacting users that don't use Monocle).

I am likely to find some time later this week/weekend to look into scalajs-react-bridge issues (this and other). But if you can make a PR (ideally along with a test(s)), that will be awesome.

from scalajs-react-bridge.

ramnivas avatar ramnivas commented on September 18, 2024

With IO removed from scalajs-react in 0.10.x and I have just added support for functions that return Callback, I think this is no longer needed. Please reopen if needed.

from scalajs-react-bridge.

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.