|
1 | 1 | package ru.org.codingteam.loglist |
2 | 2 |
|
| 3 | +import io.circe.generic.auto._ |
| 4 | +import io.circe.parser.decode |
3 | 5 | import org.scalajs.dom |
4 | | -import org.scalajs.dom.ext.Ajax |
5 | | -import org.scalajs.dom.ext._ |
| 6 | +import org.scalajs.dom.ext.{Ajax, _} |
6 | 7 | import org.scalajs.dom.{Element, Event} |
7 | 8 |
|
8 | | -import io.circe.generic.auto._ |
9 | | -import io.circe.parser.decode |
| 9 | +import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue |
10 | 10 |
|
11 | 11 | object Application { |
12 | 12 |
|
13 | 13 | def voteHandler(action: String, id: String, ratingContainer: Element)(event: Event) = { |
14 | | - import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue |
15 | | - Ajax.post(s"/api/quote/$id/$action").foreach { case request => |
16 | | - decode[QuoteRating](request.responseText).foreach { case response => |
17 | | - ratingContainer.textContent = response.rating.toString |
18 | | - } |
| 14 | + for { |
| 15 | + xhr <- Ajax.post(s"/api/quote/$id/$action") |
| 16 | + response <- decode[QuoteRating](xhr.responseText) |
| 17 | + } { |
| 18 | + ratingContainer.textContent = response.rating.toString |
19 | 19 | } |
20 | 20 | } |
21 | 21 |
|
22 | 22 | def fillSuggestedQuoteCounters() = { |
23 | | - import scala.scalajs.concurrent.JSExecutionContext.Implicits.queue |
24 | | - Ajax.get(s"/api/quote/count/suggested").foreach { case request => |
25 | | - decode[QuoteCount](request.responseText).foreach { case response => |
26 | | - dom.document.querySelectorAll(".suggested-quote-counter").map { node => |
27 | | - node.textContent = response.count.toString |
28 | | - } |
| 23 | + for { |
| 24 | + xhr <- Ajax.get(s"/api/quote/count/suggested") |
| 25 | + response <- decode[QuoteCount](xhr.responseText) |
| 26 | + } { |
| 27 | + dom.document.querySelectorAll(".suggested-quote-counter").map { node => |
| 28 | + node.textContent = response.count.toString |
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
|
0 commit comments