Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upFiery Comets: Support for AJAX responses with comets (shifted to master) #1585
Conversation
Shadowfiend
added some commits
May 1, 2014
Shadowfiend
changed the title
Fiery Comets: Support for AJAX responses with comets
Fiery Comets: Support for AJAX responses with comets (shifted to master)
Jun 21, 2014
farmdawgnation
added
WebKit
labels
Jun 28, 2014
farmdawgnation
added this to the 3.0-M2 milestone
Jun 28, 2014
This comment has been minimized.
This comment has been minimized.
It's on my to-do list to do a pass on this PR this weekend. I will (hopefully) actually get to that pass. Want to test this by building a sample project and seeing if I can break it. |
This comment has been minimized.
This comment has been minimized.
Any news? :) |
This comment has been minimized.
This comment has been minimized.
Still on my list. |
This comment has been minimized.
This comment has been minimized.
Haven't looked at the code quite yet, but I was able to do a successful test of sending down a comet via AJAX! You can find the sample project I used here: https://github.com/farmdawgnation/fiery-comets-test |
farmdawgnation
reviewed
Jul 4, 2014
* <lift:comet type=<Your comet class> name=<Optional, the name of this comet instance>>{xhtml}</lift:comet> | ||
* </pre> | ||
* {{{ | ||
* <lift:comet type="MyCometClass"> name="Optional, the name of this comet instance">{xhtml}</lift:comet> |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
farmdawgnation
reviewed
Jul 4, 2014
cometName: Box[String], | ||
cometHtml: NodeSeq, | ||
cometAttributes: Map[String, String], | ||
session: LiftSession) |
This comment has been minimized.
This comment has been minimized.
farmdawgnation
Jul 4, 2014
Member
Would we benefit from providing default attributes for any of these?
This comment has been minimized.
This comment has been minimized.
Shadowfiend
Jul 6, 2014
Author
Member
This is used internally at the moment, but has been public API since it was introduced. I'm not messing with it for now, we'll see in the future. Interactions with it should generally go through the S
methods anyway.
farmdawgnation
reviewed
Jul 4, 2014
name: Box[String], | ||
defaultHtml: NodeSeq, | ||
attributes: Map[String, String]): Unit | ||
protected def initCometActor(creationInfo: CometCreationInfo): Unit | ||
|
||
def theType: Box[String] |
This comment has been minimized.
This comment has been minimized.
farmdawgnation
Jul 4, 2014
Member
This should be changed to a String
since no-type Comets aren't supported anymore right?
This comment has been minimized.
This comment has been minimized.
Shadowfiend
Jul 6, 2014
Author
Member
I believe this is still here because I didn't get a chance to fully extricate it. Since it's rarely used except internally in comet stuff, I'd rather put off completing this removal until a later PR.
farmdawgnation
reviewed
Jul 4, 2014
case (Full(xml), _, true) => LiftRules.jsArtifacts.setHtml(id + "_outer", ( | ||
spanFunc(0, Helpers.stripHead(xml)) ++ fixedXhtml.openOr(Text("")))) | ||
spanFunc(Helpers.stripHead(xml)) ++ fixedXhtml.openOr(Text("")))) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Shadowfiend
Jul 6, 2014
Author
Member
We were using a lift:when
attribute to handle some aspects of client-side comet registration at some point in the past (in particular, I believe to indicate the current version of the comet at render time so you could get any messages after it when the browser fired up the comet connection). It's no longer used, however.
farmdawgnation
reviewed
Jul 4, 2014
true | ||
).cmd | ||
} else { | ||
js.JsCmds.Noop |
This comment has been minimized.
This comment has been minimized.
farmdawgnation
Jul 4, 2014
Member
Can we do some package imports so we don't have to mention these package names all throughout this function?
This comment has been minimized.
This comment has been minimized.
Shadowfiend
Jul 6, 2014
Author
Member
I intentionally didn't do that because it feels like this code block is doing too much JS work right now. I didn't figure out how to fix it when I first opened the PR, but I'd like for it to stand out as a sign that we should probably be doing this a different way. Hopefully I'll get to revisit it at some point, since I think there's still some good comet work to be done.
This comment has been minimized.
This comment has been minimized.
farmdawgnation
reviewed
Jul 4, 2014
|
||
attemptedComet match { | ||
case fail @ Failure(_, Full(e: java.lang.NoSuchMethodException), _) => | ||
val message = s"Failed to find appropriate comet constructor for ${cometClass.getCanonicalName}. Tried no arguments and (LiftSession, Box[String], NodeSeq, Map[String,String])" |
This comment has been minimized.
This comment has been minimized.
farmdawgnation
Jul 4, 2014
Member
Do you think the added information about which variants of constructors were tried will be valuable to the end user? Seems like something that could quickly become a lie (constructors change, message doesn't). Would it inform their action?
This comment has been minimized.
This comment has been minimized.
Shadowfiend
Jul 6, 2014
Author
Member
It is a huge hint on what actually went wrong, and I think more detail is always a better move in cases where we're trying to implicitly invoke something without the user telling us that's what we should be invoking. Moreover, I think essentially nobody will run into this particular issue, as a no-arg constructor is the way most people use comet actors. In the future, it might be worth exploring how to unify the message with the code to make it harder to let those two get unsynced.
Also fingers crossed on code review catching such a change, of course ;)
This comment has been minimized.
This comment has been minimized.
farmdawgnation
Jul 7, 2014
Member
Ahhhhhhhh ok, after chatting with you I now understand how this error is generated. I didn't previously... read like something internal that the user couldn't fix. Perhaps this message could read...
Couldn't find valid comet constructor for ${cometClass.getCanonicalName}. Comets should have a no argument constructor or one that takes the following arguments: (LiftSession, Box[String], NodeSeq, Map[String,String]).
How does that sound?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
A broad comment before I respond on more specific stuff: my general policy when working on Lift is “clean up/refactor as much as I'm motivated to in a given pass”. Other folks are welcome to do additional cleanup and refactoring, but don't be surprised if I turn down the option of doing additional work on a given corner that's unrelated to the feature work. |
This comment has been minimized.
This comment has been minimized.
Hey Antonio, if you can give me your thoughts on this line comment - that's the only thing I want an answer on before merging this. :) |
Shadowfiend commentedJun 20, 2014
This is #1565 reopened with respect to
master
.To support AJAX responses that send down comets, this PR actually
refactors a few aspects of comet creation:
LiftSession
now has a new internal (private) API for finding or creatinga comet. There are two variations of
findOrCreateComet
, one that takesa type parameter (
findOrCreateComet[MyCometType](name, html, attributes)
)and one that takes a string comet type (
findOrCreateComet("MyCometType", ...)
)The type parameter version uses manifests to allow direct instantiation of a
comet without reflection overhead and without requiring the comet to be in the
regular comet package if not wanted.
LiftSession
's comet-related code has been significantly refactored toeliminate duplication and make things a little easier to follow. Notably, there
are still some anonymous subclasses of
CometActor
created for round-tripsand streaming promises; those will be refactored to independent subclasses
at some point, but I didn't do it in this PR.
CometId
to representit in
LiftSession
.CometCreationInfo
case class, which was in theTemplates.scala
file, isnow in the
CometActor.scala
file, and is used pervasively to pass comet creationinfo around (before, we were using separate parameters in many places). This is
still mostly an internal class, however.
S
has a new API for finding or creating a comet,S.findOrCreateComet
.It works much like the
LiftSession
API, taking either a type parameter or a stringthat is a comet class's name. Both of the overloads also have a
receiveUpdatesOnPage
parameter that is defaulted tofalse
. When set totrue
,it will automatically append the created
CometActor
to the page or AJAX requestso that it will receive updates.
S
also has a method for adding a comet to the currently rendering page or pagethat invoked the current AJAX callback,
S.addComet
. It takes aLiftCometActor
,which you can get from
S.findOrCreateComet
if you don't have a direct handleto it already.
request, mostly in order to support restarting the current comet cycle. This is used
when a new comet is received from the server to ensure the comet starts receiving
updates immediately.
It also now has a
containerForCometActor
method that is publicly available andlets you get the HTML container for any given comet actor. This lets you do your
own work to create a comet container without directly invoking the comet snippet.