[英]Scala + Play Framework: Action composition explanation needed
這是Play框架隨附的示例中的動作組成
def IsAuthenticated(f: => String => Request[AnyContent] => Result) = Security.Authenticated(username, onUnauthorized) { user =>
Action(request => f(user)(request))
}
因此, Security.Authenticated
使用username: RequestHeader => Option[String]
, onAuthorized: RequestHeader=>SimpleResult
,第二組括號采用String => Action[A]
然后在控制器中,我有:
def index = isAuthenticated { ...code }}
上面的代碼是這個,所以我假設這是f
函數=> String => Request[AnyContent] => Result
。 現在,我不明白的是這里真正發生的事情。 我不是在談論User.findByEmail....
,我是在談論username => _ => ...
如果直接調用此函數,其簽名將是什么樣?
username => _ =>
User.findByEmail(username).map { user =>
Ok(
html.dashboard(
Project.findInvolving(username),
Task.findTodoInvolving(username),
user
)
)
}.getOrElse(Forbidden)
如果有def isAuthenticated(f: => Request[AnyContent] => Result)
我會知道如何使用它並且我會理解。 但是多余的“數據”使我感到困惑。
更新:
我想我發現了一些東西:
def f2: String => Int => List[Char] = x => _ => x.toList
這將被稱為:
f2("Andrew")(2) //there can be anything replacing 2 because I don't have access to it anyway
所以上面我主要詢問的功能是:
def f: => String => Request[AnyContent] => Result = username => _ => User.find.....
我對嗎?
我收到“此處不允許使用名稱參數錯誤”。
如果他們不使用第二個參數,為什么要使用String => Request => Result
而不僅僅是String => Result
?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.