Giter Site home page Giter Site logo

Comments (16)

Atry avatar Atry commented on May 27, 2024

See #185

from binding.scala.

glmars avatar glmars commented on May 27, 2024

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.

Atry avatar Atry commented on May 27, 2024

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.

glmars avatar glmars commented on May 27, 2024

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.

datalchemist avatar datalchemist commented on May 27, 2024

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.

Atry avatar Atry commented on May 27, 2024

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.

datalchemist avatar datalchemist commented on May 27, 2024

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.

Atry avatar Atry commented on May 27, 2024

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.

Atry avatar Atry commented on May 27, 2024

MountPoint is designed to integrate Binding to another system.

from binding.scala.

glmars avatar glmars commented on May 27, 2024

@datalchemist

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.

Atry avatar Atry commented on May 27, 2024

If you just need to trigger some HTTP request, you can use FutureBinding.
For example: https://scalafiddle.io/sf/TKPExZE/4

from binding.scala.

datalchemist avatar datalchemist commented on May 27, 2024

@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.

datalchemist avatar datalchemist commented on May 27, 2024

@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.

Atry avatar Atry commented on May 27, 2024

@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.

datalchemist avatar datalchemist commented on May 27, 2024

@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.

Atry avatar Atry commented on May 27, 2024

Now there is a NodeBinding, which has a public value, for @html XML literals

https://javadoc.io/static/org.lrng.binding/html_sjs0.6_2.13/1.0.3+56-51cfb24a/org/lrng/binding/html$.html#:~:text=to%20create%20ElementBuilder-,%EE%85%97,-type

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.