lift/framework — pull request #1607 by Shadowfiend (2014-08-09 17:00:07+00:00)
Title: Lazy Susan: Implement lazy-load and future CanBind support in AJAX responses

This PR really does three things:
- Reworks the `LazyLoad` snippet and separates out the `AsyncRenderComet` to its own
file. This refactoring allows the `LazyLoad` snippet to work even if you're rendering an AJAX
response, thanks to the fiery comets work that went in a few weeks ago.
- Adds a `CanResolveAsync` type class that can be used to handle any object that can be
resolved to a value asynchronously in the same way. Right now, two `CanResolveAsync`
implicits are provided: one for Scala `Future` and one for `LAFuture`.
- Adds a `CanBind` for any type that has a `CanResolveAsync` implicit defined for it. This
uses some of the helper functions exposed by `AsyncRenderComet` to handle asynchronously
sending down the results of resolving the object in question.

Concretely, this means four big things:
- `LazyLoad` now works correctly even if it's rendered during an AJAX response. This wasn't
the case in Lift 2.x.
- You can use Scala `Future` and `LAFuture` on the right-hand-side of a CSS selector transform
out-of-the-box. Like @fmpwizard's original implementation and unlike my dirt-simple one, this
does not waste a thread trying to resolve the futures.
- Those futures can be used even if rendering during an AJAX response. I know my implementation
couldn't do this, I didn't check if Diego's could.
- Support for additional future-like types (for example, Twitter `Future`s as used by Finagle) is
just a matter of providing a `CanResolveAsync` implicit. Their implementations are incredibly
simple (they are simply abstractions over `onSuccess` or whatever equivalent is provided).