Configuring lift.js

82 views
Skip to first unread message

Joe Barnes

unread,
Jan 23, 2016, 5:20:19 PM1/23/16
to Lift
I'm getting back to reviewing how we let the end developer configure the lift.js front-end code.  Lift 3.0 introduces a complete rewrite of this mechanism in Lift (thanks Tim!), but unfortunately it hides a few things I've taken advantage of in lift-ng.  As you can see in liftproxy.js, I take advantage of the public nature of the lift javascript objects.  In particular, I add success and error callbacks for both ajax and comet, and I implement my own retry queue ordering (lift-ng has a feature to guarantee messages arrive in order).

I explored how we can do this better a little bit in this PR but you can see I backed off it during the discussion of this PR.  I still need to solve this problem before Lift 3.0 goes out, otherwise there are features of lift-ng that will never work (or I could just copy/paste the entire lift.js into lift-ng but I doubt anyone would like that approach)

It appears that it is possible for me to provide the ajax success and failure callbacks here.  I could also probably hook into comet failures here (but no comet success).  However, there is certainly no way to take over the message queue.  

Adding a comet success callback seems easy enough.  I'd like to know what everyone thinks about the queue.  Guaranteeing message order seems to be a common enough behavior that I could implement what I have in lift-ng in Lift itself and offer it as a setting.  That would be easier to design than exposing the queue in a sane fashion to allow custom ordering.  Or maybe I can see a clean way to expose it and provide guaranteed message order as an out-of-the-box available configuration.

Joe

Antonio Salazar Cardozo

unread,
Jan 24, 2016, 6:06:45 PM1/24/16
to Lift
Everything ultimately goes through `settings.ajaxGet`. So I think you should be
able to replace Lift's default behavior by simply replacing settings.ajaxGet to
intercept the success and failure functions and switch them out accordingly,
probably?
Thanks,
Antonio

Joe Barnes

unread,
Jan 24, 2016, 6:41:44 PM1/24/16
to Lift
You are right, but it doesn't quite accomplish what I need.  It turns out I wasn't quite clear earlier.  After going through the code today, I see that I had forgotten the details of my use case.

What I am trying to capture is server communication issues, not request-specific failures.  The use case would be to have a warning message that the page is struggling to communicate with the server, much like apps such as Trello does.  The two callbacks exposed by the ajax call are only used after the request has succeeded or been bailed on.  Hence if I make my app much more patient with failures (retrying for several minutes even), then I have no good way to let the user know that things aren't going so well.

What I really need is to know every time that communication with the server has failed or succeeded.  That means I need hooks down into the appendToQueue function.  On my working branch at the moment, I have updated that function to notify configured functions when an ajax request fails, for instance.  Registering is as simple as passing your function to lift.ajaxOnCommFailure().

Joe

Joe Barnes

unread,
Jan 24, 2016, 7:45:07 PM1/24/16
to Lift
Since the server communication callbacks and message ordering are two separate features, I have opened a PR with the code for the callbacks.

Joe

Antonio Salazar Cardozo

unread,
Jan 25, 2016, 9:46:19 PM1/25/16
to Lift
I'm still not following. ajaxGet and ajaxPost are the things that are invoked on any
AJAX activity Lift attempts. This means you can wrap the success and failure callbacks
there to do whatever you need to, including ignore Lift's own retry mechanics (which are
passed as failure callbacks). That seems sufficient, but it's possible I'm just being thick :)
Thanks,
Antonio

Joe Barnes

unread,
Jan 25, 2016, 10:34:03 PM1/25/16
to lif...@googlegroups.com
For onSuccess, yes you are right.  But onFailure is not called until all attempts have been exhausted.  I would like notification that we are in a state of retrying before we begin bailing on requests.

Joe


--
--
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 a topic in the Google Groups "Lift" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/liftweb/0z6SV0ucEW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonio Salazar Cardozo

unread,
Jan 26, 2016, 1:45:44 PM1/26/16
to Lift
I still think we're not on the same page :) You're looking at doAjaxCycle. doAjaxCycle,
when it calls into the server, calls settings.ajaxPost and passes it the internal
doAjaxCycle success and failure handlers that do Lift's retry logic. You can
replace settings.ajaxPost to plug in your own retry logic, as it's the lowest level
function: the one that actually does the AJAX call. Similar idea for ajaxGet and
comet requests. Just either ignore or wrap the parameters you're given.
Thanks,
Antonio
To unsubscribe from this group and all its topics, send an email to liftweb+unsubscribe@googlegroups.com.

Joe Barnes

unread,
Jan 26, 2016, 10:06:39 PM1/26/16
to lif...@googlegroups.com
I wish I had a clever meme for the aha moment I had reading your email. :)  You're talking about this guy.  And now I get how I should be doing this.

Similarly, I can hook into comet via settings.httpGet.  

I do believe we can nullify this PR!

Joe


To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
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 a topic in the Google Groups "Lift" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/liftweb/0z6SV0ucEW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.

Antonio Salazar Cardozo

unread,
Jan 26, 2016, 10:58:14 PM1/26/16
to Lift
You know, now that you've done it, it seems obvious that I should have linked to the
relevant code in the repo :)
Thanks,
Antonio
To unsubscribe from this group and all its topics, send an email to liftweb+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
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 a topic in the Google Groups "Lift" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/liftweb/0z6SV0ucEW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to liftweb+unsubscribe@googlegroups.com.

Joe Barnes

unread,
Jan 27, 2016, 7:34:08 AM1/27/16
to lif...@googlegroups.com
No problem.  You're just giving me an opportunity to get better at finding my way around the Lift source. :D

Antonio
To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
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 a topic in the Google Groups "Lift" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/liftweb/0z6SV0ucEW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
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 a topic in the Google Groups "Lift" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/liftweb/0z6SV0ucEW4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.

Joe Barnes

unread,
Feb 6, 2016, 12:27:20 AM2/6/16
to Lift
Hey Antonio,

I started to give this a look and I feel I'm still missing something.  In this branch of my sample repo, I tried to forcibly override ajaxPost.  I can see the expected result in the page's js in the browser:

"ajaxPost": function() {console.log("hijacked!!");}


But unfortunately, this happens next:

window.lift.extend(lift_settings,window.liftJQuery);

Which the obliterates my ajaxPost.

From what I see in LiftJavaScript.scala, the second extend is unavoidably the second thing that happens.  I would assume that I shouldn't be aiming to mutate the liftJQuery and liftVanilla objects to accomplish my goal.  It seems impossible to inject code after those two are defined but before the extend code runs.  

It's at this point that I feel I've missed something again and I'm probably better off admitting it's time to politely ask for direction. :)  So let me know if you or anyone else eavesdropping the conversation have an idea.

Joe

To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.

Antonio Salazar Cardozo

unread,
Feb 7, 2016, 1:16:18 PM2/7/16
to Lift
Whoops. No, I'd say this is actually a mistake in LiftJavaScript. I think if you switch
these two lines your stuff should be running *after* we do Lift's internal JS setup, which
I consider to be correct behavior since the whole point of letting you customize the
JS settings is so you can override Lift's defaults :)
Thanks,
Antonio

Joe Barnes

unread,
Feb 7, 2016, 2:42:28 PM2/7/16
to lif...@googlegroups.com
Alright, I felt that might be the case but wasn't sure.  I imagine we might've accidentally got things out of order during some of the massive refactoring for Lift 3.0.  I'll give it a look once I get my head out of comet rehydration. :)

Joe

Antonio Salazar Cardozo

unread,
Feb 7, 2016, 2:53:39 PM2/7/16
to Lift
Awesome :) First fix for the RC!
Antonio
To unsubscribe from this group and all its topics, send an email to liftweb+unsubscribe@googlegroups.com.

Joe Barnes

unread,
Feb 7, 2016, 4:20:38 PM2/7/16
to lif...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages