Comments (16)
See #185
from binding.scala.
Oh! Thanks, now I understand the reason why you have reverted the commit. So, it is possible to implement this only in the next minor/major version!?
from binding.scala.
If think a better approach is to create some test library that contains public functions to extract/verify current value of a Binding
.
Other usages of value
in Binding
are likely unsafe to me, resulting unexpected behaviors.
from binding.scala.
A good idea! I think this library can make writing tests easier by hiding some details, such as b.watch ()
, b.get.outerHTML
, etc.
from binding.scala.
On my side, I had the same need for a different use-case.
In short, I used Binding
for mapped Var
using a pattern like val myMappedVar = Binding(transform(myVar.bind))
And then, I needed to use this myMappedVar
both for rendering html dom (which is perfectly fine) but also in some other actions in which I just needed to get the current mapped Var value (which is not possible).
In the end, the only solutions I found was either to recompute each time the mapped var value (introducing time overhead), or to use an additional Var
to store the mapped value (which leads to a memory overhead)
At some point, I wondered whether there could not be some feature to handle such cases. For example, we could have a method map[B](f: A=>B)
defined for Var[A]
which would return some VarLike[B]
which still offers value
but not value_=
.
from binding.scala.
but also in some other actions in which I just needed to get the current mapped Var value
Sounds like a misusage.
from binding.scala.
but also in some other actions in which I just needed to get the current mapped Var value
Sounds like a misusage.
Maybe, it is...or maybe it is a kind of over-usage.
More concretely, my scenario is the following:
I have a large & complex data model (a graph of entities) from which I derive simpler data structures (like a list of specific entities in the graph). Then, I use these derived data for display (in dom methods) but also for performing some event-based computations on it (for example, I want to perform a complex search in these derived data in response to some event)
I put the whole graph in a Var
because I want to be reactive with full graph update. And so, my point is that currently, I have to put also these derived data in "intermediary" Var
which have no other purpose than providing me with the current value of these data. Actually, I have developed several generic things on top of Binding.scala to achieve these things and others in a generic way, and in practice, this works quite well...but I am not fully satisfied because I don't know how to do without these half-used Var
.
I would be glad to hear if you have other idea on how to approach this kind of scenario.
from binding.scala.
Then, I use these derived data for display (in dom methods) but also for performing some event-based computations on it (for example, I want to perform a complex search in these derived data in response to some event)
Try MountPoint
from binding.scala.
MountPoint
is designed to integrate Binding
to another system.
from binding.scala.
I use these derived data for display (in dom methods) but also for performing some event-based computations on it (for example, I want to perform a complex search in these derived data in response to some event)
Please, post your code here. It's possible to implement search without using of Binding.value
from binding.scala.
If you just need to trigger some HTTP request, you can use FutureBinding
.
For example: https://scalafiddle.io/sf/TKPExZE/4
from binding.scala.
@Atry Thanks for the pointers!
I will definitely have a closer look at these two things (MountPoint
and FutureBinding
) I'm not sure they will solve the particular kind of scenario I am referring to here, but they will certainly be useful for me for other problems in which I implemented custom-made solutions.
from binding.scala.
@glmars It's not easy to give a meaningful code snippet because it is quite integrated within a quite large project with some generic part. Moreover, after looking back in this project (because I am not currently working on it) I realize I spoke a bit fast. This specific search issue is no more an issue because now, I anyway use a new Var
in order to store a sorted version of my data, and so I can do my search directly on this sorted Var
.
But anyway, the point remains and I don't see how you would implement search without using Binding.value
. Here is a short fake code to illustrate more concretely my point:
class MyView(values : Binding[Seq[Data]]) {
@dom def renderTable() =
<table><tbody>{values.bind.map(d => renderRow(d).bind)}</tbody></table>
//following function would be called from an event handler of some button somewhere else
def search(txt:String) ={
values.value.find(d => compareData(d,txt))
}
}
On a more general side, I actually encountered similar problems in different situation. Here again, I provide some fake code to illustrate it:
//large graph object
val graph : Var[GraphData]
//enriched version resulting from computations on simple graph
val enrichedGraph : Binding[EnrichedGraph] = Binding(complexComputation(graph.bind))
//at some point enriched version is used to be displayed in a dom
@dom def render()={
...
{enrichedGraph.bind ..... }
...
}
//at some completely other location, we have a form (which display other data)
//...but for which we will need the enriched graph content to validate the form values
@dom def renderEntityForm() = {
<form>
...
<button onclick={e:Event =>
/* do complex validation on the form values using the content of the enriched graph,
e.g. checkForUniqueName(nameFieldValue,enrichedGraph.value)
*/
}> </button>
</form>
}
from binding.scala.
@datalchemist I think you might need a search handler which is changing according to the upstream data.
def search: Binding[String => Data] = Binding {
val snapshot = values.bind;
{ (txt: String) =>
snapshot.find(d => compareData(d, txt))
}
}
from binding.scala.
@Atry Thanks for your response! That's a good idea that I didn't think of, and it solves most of my use-cases.
However, I note that I still need to bind the search handler somewhere in order to use it, which prevents me from using it outside of a dom context.
from binding.scala.
Now there is a NodeBinding
, which has a public value
, for @html
XML literals
from binding.scala.
Related Issues (20)
- FXML: Enable opening pop-up window at a specified location
- Null cache exception in FlatMap HOT 8
- Entity references in attribute values do not compile
- Referring to non-existent method com.thoughtworks.binding.FutureBinding$.apply(scala.concurrent.Future,scala.concurrent.ExecutionContext) HOT 1
- Event handlers in custom tags HOT 1
- data prefix does not (it should) set the attribute to null if the initial value is null HOT 1
- FutureBinding compare with React hooks HOT 1
- Vars.all is not triggerred HOT 2
- := deprecated, how to use value_= ? HOT 3
- dom module is missing for version `12.0.0-M0` HOT 1
- V12 eta HOT 2
- Vars size binding HOT 3
- Conversion from Binding[Iterable[A]] to BindingSeq[A] HOT 4
- Using BindingSeq in an implicit value class HOT 1
- Use @html to create a table, what is returned is scala.xml.NodeBuffer, and what is needed is BindableSeq[org.scalajs.dom.Node], how to convert? HOT 4
- Dependency `scalajs-dom` is out dated HOT 1
- The last element in HTML interpolation are inserted twice (Binding.scala 13.x)
- Code in `ReadMe.md` failed for unkonow reason. HOT 8
- Support for `Scala.js1.x` & `Scala2.12`
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 binding.scala.