Skip to content

Instantly share code, notes, and snippets.

@heralight
Last active December 10, 2016 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heralight/2fc580d0a12ed4cb6f09 to your computer and use it in GitHub Desktop.
Save heralight/2fc580d0a12ed4cb6f09 to your computer and use it in GitHub Desktop.
Tips to Upgrade a liftweb application from 2.5 2.6 to version 3

Some tips to upgrade your lift 2.5 2.6 application to lift 3 (3.0-SNAPSHOT, 3.0-M2, ...etc)

MongoDb

replace ensureIndex( by createIndex( replace setIsUnset( by setIfUnset(

New Features

Promise Actor

  for (sess <- S.session) {
    val roundTrip = sess.buildRoundtrip(List[RoundTripInfo](
      "loop" -> doLoop _,
      "findUser" -> doFindUser _,
    ))}

Rest Promise

object DelayedRest extends RestHelper {
  serve {
    case "delay" :: Nil Get _ =>
    LAFuture(() => {
      Thread.sleep(2000)
      <b>Hello</b>})
  }
}

http://lift.la/blog/lift_30

Renaming

updateListeners to sendListenersMessage

  • JsonHandler => replaced with RoundTrips and SHtml.jsonCall
  • jsonCall => jsonSend
  • CometActor handleJson => receiveJson

Markdown

remove EmbedMD and use template md from lift core support.

<div data-lift="embed?what=/docs/about-dev-text"></div>

Box

No more get, you can replace it by openOrThrowException("some msg")

JSon

val v = "user" -> u.asJValue ~
 ("whenCreated" -> "someDate"))
// { "user" { "some JValue Fields u.asJValue" , "whenCreated" : "someDate"  }}

is now :

val v = "user" -> (u.asJValue ++
 ("whenCreated" -> "someDate")))

will produce an JArray

or for a JObject

val v = "user" -> (u.asJObject ++
   ("whenCreated" -> "someDate")))

where asJObject is :

   import net.liftweb.common._
   import net.liftweb.http._
   import S._
   import net.liftweb.json.JsonAST.JObject
   import net.liftweb.json._
   import net.liftweb.record.{MetaRecord, Record}
   import net.liftweb.util._
   import Helpers._
   import scala.xml._

   trait RecordExt[BaseRecord <: Record[BaseRecord]] extends Record[BaseRecord] {
     self: BaseRecord =>

     def meta: MetaRecord[BaseRecord] with MetaRecordExt[BaseRecord]

     /** Encode a record instance into a JObject */
     def asJObject(): JObject = {
       meta.asJObject(this)
     }
   }


   trait MetaRecordExt[BaseRecord <: Record[BaseRecord]]  extends MetaRecord[BaseRecord]  {
     self: BaseRecord =>

     /** Encode a record instance into a JObject */
     def asJObject(rec: BaseRecord): JObject = {
       JObject(fields(rec).map(f => JField(f.name, f.asJValue)))
     }
   }

https://groups.google.com/forum/#!searchin/liftweb/JValue$20lift$203$20~$20/liftweb/b0uIqoUi2ck/O0acAaZOscAJ

Template

Surround have a new attribute eat to to drop the element that invoked the surround. The at attribute of surround is bind to element id. <lift:bind> disappears.

Wizard

Now include in lift core, no more sbt adds like lift-wizard. wizard html template integrate new lift 3 constraints, no more specific lift node. New example at : https://github.com/tuhlmann/lift-3-demo/blob/master/src/main/webapp/templates-hidden/wizard-all.html

Test

mock Request replace mockReq.body = s by mockReq.body_(s)

New deprecations

JSONParser, Lift's legacy JSON parser, along with its dependents:
    MetaRecord.setFieldsFromJSON
    MetaRecord.fromJSON
    CometActor's handleJson, jsonCall, and jsonInCode
    S.buildJsonFunc
    S.jsonFmapFunc with Any=>JsCmd
    JsonHandler
    SHtml.fjsonCall
    SHtml.jsonButton with Any=>JsCmd
    SHtml.jsonForm
Mapper and MetaMapper's snippet bindings that use PartialFunctions:
    addSnippet, editSnippet, viewSnippet (in favor of addFormSnippet, editFormSnippet, andviewTransform, all based on CSS selector transforms)
    modSnippet, used in addSnippet and editSnippet, superseded by formSnippet.
    add, edit, and view snippets in HTML, in favor of addForm, editForm, and viewTransform
    fieldMapperPF, in favor of fieldMapperTransforms
    fieldPF, appendField, and prependField, in favor of fieldTransforms, appendFieldTransform, and prependFieldTransform.

Reference:

@Shadowfiend
Copy link

Ran across this via Google; nice recap!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment