How to use IdMemoize with partialUpdate?

34 views
Skip to first unread message

Dan Gravell

unread,
Jul 20, 2016, 7:00:54 AM7/20/16
to Lift
I have a page with search results, with the search results taking a while to query.

In this page I want to use a comet actor and partialUpdate to drip feed results in, fading them in with JQ. I have a list of results maintained in the actor. I don't want to use setHtml and re-render because that simply overwrites the HTML with the block of results. I want to use a NodeSeq that captures the template to apply to the results.

So in render I have something like:

    ".div-results" #> SHtml.idMemoize { outer => {
      resultsDiv = Some(outer)
      results.map(thumbnailCss)
    }}

thumbnailCss is a function returning a CssSel.

That works if the results are already in. Now in my message handling I want something like:

      resultsDiv.map(div => ???)
      .foreach(thumbnailNodeSeq => 
       partialUpdate(addResult(thumbnailNodeSeq))
      )
    }

In the place of ??? I tried:

    thumbnailNodeSeq.apply(div.latestKids)

But that gave an AbstractMethodError!

Is there a way of doing this?

Dan

Matt Farmer

unread,
Jul 20, 2016, 9:26:20 AM7/20/16
to Lift
I don’t know about others, but I’m having a hard time picturing what you’re talking about.

Is there any chance you could set up a barebones example project or something I could look at so I can understand?


Matt Farmer | Blog | Twitter
GPG: CD57 2E26 F60C 0A61 E6D8  FC72 4493 8917 D667 4D07

--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code

---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Gravell

unread,
Jul 20, 2016, 12:27:42 PM7/20/16
to Lift
Hmmm, sorry, thought this would be straightforward. I'll try to put something together tomorrow morning. To make sure I don't miss anything in the simplification process, which part of it don't you understand - the comet messaging bit, the initial render bit?

Diego Medina

unread,
Jul 20, 2016, 1:49:09 PM7/20/16
to Lift
Dan,

while you get the example ready, quick question, why are you using idMemoize? idMemoize is usually used when you want to refresh the content of the page using ajax, all at once.

If you want to use comet, just use comet, the render method on the comet does the initial rendering of the results page and then you can use  partialUpdate to send the JsCmd that will add a new row of data.
If you go down this road, I tend to send json data for the new data and I trigger an event on the client side, then I write plain old js/jQuery on the client side to listen for that event, and then take the json and add it to the page.

Awhile ago I wrote a few posts that may help you, even though those were for Lift 2.5, they still work for 3.x


Hope that helps.

Diego




--
Diego Medina
Lift/Scala Consultant
di...@fmpwizard.com
http://blog.fmpwizard.com/

Dan Gravell

unread,
Jul 21, 2016, 3:45:48 AM7/21/16
to Lift
I'm using idMemoize because I want to re-use the same portion of the template without repeating it.

Oh, hang on, I could just do a ".selector" #> ((ns:NodeSeq) => createCssSel) in the render(), capture ns and apply ns to createCssSel in the partialUpdate, couldn't I?

D'oh... talk about choosing the complicated path.

Dan

Dan Gravell

unread,
Jul 21, 2016, 5:14:59 AM7/21/16
to Lift
That worked, sorry for wasting everyone's time. 

One point on API usage. In the render I found I had to do:

    ".div-results" #> ((ns:NodeSeq) => {
      resultsDiv = Some(ns)
      results.map(thumbnailCss).map(_.apply(ns))
    })

I found I had to make the "apply" call because otherwise the compiler didn't like the RHS of the CssSel to be NodeSeq => List[CssSel] . So using apply changed it to NodeSeq => List[NodeSeq] which it liked. Hope that's ok, not sure if I can save some code there.

Dan

Diego Medina

unread,
Jul 22, 2016, 10:05:59 PM7/22/16
to Lift
Thanks for posting the working code!
Reply all
Reply to author
Forward
0 new messages