Comments (5)
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.
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.
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.
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.
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)
- React.createElement error while porting react-bootstrap component HOT 10
- sbt unresolved dependency HOT 5
- Provide JsWriter for the union type HOT 2
- New Release HOT 1
- withKey HOT 2
- ScalaJsReact 1.2.0 HOT 3
- How to setup components to be wrapped HOT 2
- () => Unit as Callback HOT 2
- Declare render functions HOT 2
- Document value toJs is not a member of <notype> error
- Document importing NPM dependencies HOT 1
- js.native dependencies in render HOT 2
- scalajs-react 1.4.0 HOT 1
- Publish for 2.13.0 HOT 2
- Publish for scalajs 1.0 HOT 7
- Set up Scala Steward HOT 1
- Regression on <notype> issue
- Key property doesn't get applied to react bridge components
- Publish new version with sjs1 support. HOT 3
- Getting `Ref` of a bridge component HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scalajs-react-bridge.