JsCmd如何在Lift工作?

Rob*_*een 0 scala lift

我认为它将附带的代码编译成Javascript,但代码是如何编译而不是执行的?例如,Simply Lift的代码:

object AjaxExample {
  def render = {
    // state
    var name = ""
    var age = "0"
    val whence = S.referer openOr "/"
?
    // our process method returns a
    // JsCmd which will be sent back to the browser
    // as part of the response
    def process(): JsCmd= {
?
      // sleep for 400 millis to allow the user to
      // see the spinning icon
      Thread.sleep(400)

      // do the matching
      asInt(age) match {
        // display an error and otherwise do nothing
        case Full(a) if a < 13 => S.error("age", "Too young!"); Noop
?
        // redirect to the page that the user came from
        // and display notices on that page
        case Full(a) => {
          RedirectTo(whence, () => {
            S.notice("Name: "+name)
            S.notice("Age: "+a)
          })
        }

        // more errors
        case _ => S.error("age", "Age doesn't parse as a number"); Noop
      }
    }
?
    // binding looks normal
    "name=name" #> SHtml.text(name, name = _, "id" -> "the_name") &
    "name=age" #> (SHtml.text(age, age = _) ++ SHtml.hidden(process))
  }
}
Run Code Online (Sandbox Code Playgroud)

pr1*_*001 5

JsCmd不编译或执行任何操作.相反,它是一种更加类型安全的构造Javascript字符串的形式,可以将其发送到浏览器,在那里它们可能被执行.