Simple way to add comet using AJAX in Lift-3

31 views
Skip to first unread message

Andreas Joseph Krogh

unread,
Jul 27, 2014, 9:52:21 AM7/27/14
to lif...@googlegroups.com
I cooked up this:
 
    case class RegisterComet[T <: LiftCometActor](id: String, name: String, kids: NodeSeq)(implicit cometManifest: Manifest[T]) extends JsCmd {
        val castClass = cometManifest.runtimeClass.asInstanceOf[Class[T]]
        override val toJsCmd = {
            val cometMarkup = S.findOrCreateComet[T](Full(name), kids, Map.empty, receiveUpdatesOnPage = true).map{comet=>
                S.addComet(comet)
                Comet.containerForCometActor(comet)
            }.getOrElse(<div>Could not find or create comet for type {castClass.getSimpleName} with name {name}</div>)
            Replace(id, cometMarkup).toJsCmd
        }
    }
 
 
Should we provide something similar out of the box in Lift-3?
 
--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963

Antonio Salazar Cardozo

unread,
Jul 27, 2014, 11:31:49 AM7/27/14
to lif...@googlegroups.com
Looks really sweet, would definitely love to see a pull request with this! Probably could use a little tweaking on the
class name and some of the variable names, but I can easily see it being a common use case. Fiery Comets focused
on supporting sending comets down that don't have associated markup—something we didn't support at all before—and
this is in a sense the missing piece to make the AJAX comet story complete.

Itt's worth mentioning that you shouldn't have to S.addComet if you set receiveUpdatesOnPage as true. May be worth
clarifying the Scaladocs a little around that.
Antonio
Reply all
Reply to author
Forward
0 new messages