New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
custom snabbdom props module #108
Conversation
b85a3b8
to
023f2e7
Compare
here is an example of how to have custom javascript resources: https://github.com/scalacenter/scalajs-bundler/tree/master/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources |
26aae08
to
c369c47
Compare
After reading snabbdom/snabbdom#345, I'd like to do some benchmarking on how this affects the performance for patching larger |
@cornerman which properties are used by outwatch? |
only these five props: value, checled, selected, textContent, indeterminate. If we wanted we could also use the prop module for the reflected attributes, but there we currently use attributes. |
The current alternatives to the custom snabbdom-module are:
Before taking the time to benchmark this approach, are there any other (theoretically) faster alternatives? |
exactly, the private val valueSyncHook: (VNodeProxy, VNodeProxy) => Unit = (_, node) => {
node.elm.foreach { elm =>
val input = elm.asInstanceOf[HTMLInputElement]
if (input.value != input.getAttribute("value")) {
input.value = input.getAttribute("value")
}
}
} |
Agreed, all alternatives for keeping the DOM in sync seem to have similar trade-offs. Except that with the current snabbdom props, the DOM So, I don't know what the performance of the Just occurred to me about reflected attributes... what is the performance of updating an attribute vs updating a prop (with the current snabbdom props module). Would the performance be better to use props instead for reflected attributes ( since most reflected attributes don't get changed by another agent) |
I don't understand what you are trying to say here. Most keystrokes on an input field change the value. So it only skips in the rare cases of keys which don't change it (e.g. arrow keys). Am I overlooking something? |
I was thinking of the current props implementation that handles input(tpe := "text", value <-- strHandler, onInputString --> strHandler), there is no DOM prop write on each keystoke, only a DOM prop read. ... but that's exactly what the proposed props module does too. And since outwatch is only updating 5 props though the props module and the rest are reflected attributes, I'm not so worried any more about the performance impact (I was forgetting earlier that we're using reflected attributes for all other props and I was worried about the performance impact of reading the DOM when updating each of them). |
This is still a valid question, but I do not know of any benchmarks and how syncing between props and attributes actually behaves. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
542b3d0
to
5824d7a
Compare
The ground truth is now the dom instead of the vdom. This allows to handle user input easily and correctly.
5824d7a
to
2552ae4
Compare
As discussed in #105, this adds a custom snabbdom props module, which compares against the actual element property.
Please do not merge, as I think, the generated code for scala-js is not as performant as a pure javascript implementation. So, we should implement this module in js and somehow include it with scalajs-bundler/webpack.
What do you think?