我正在尝试将Binding.scala与现有的http4s后端服务一起使用,但我不知道如何将它们组合在一起。我不确定如何将fs2 Task或猫效应IO与Binding.scala“绑定”。
发布于 2018-01-26 03:40:25
我从未使用过http4s,但可以给出一个提示,可以使用FutureBinding。
只要你得到了一个Future,你就可以很好地使用它:
下面是我调用异步Here服务的示例(ajax-call):
@dom def afClients(): Binding[HTMLElement] = {
val apiPath = s"/calendar/afClients"
FutureBinding(Ajax.get(apiPath))
.bind match {
case None =>
<div class="ui active inverted dimmer front">
<div class="ui large text loader">Loading</div>
</div>
case Some(Success(response)) =>
val json = Json.parse(response.responseText)
info(s"Json received List[AFClientConfig]: ${json.toString().take(20)}")
json.validate[List[AFClientConfig]] match {
case JsSuccess(u, _) =>
changeAFClients(u)
<div>
</div>
case JsError(errors) =>
<div>
{s"Problem parsing User: ${errors.map(e => s"${e._1} -> ${e._2}")}"}
</div>
}
case Some(Failure(exception)) =>
error(exception, s"Problem accessing $apiPath")
<div>
{exception.getMessage}
</div>
}
}https://stackoverflow.com/questions/44642173
复制相似问题