<commit_before>package live

import java.util.concurrent.ThreadLocalRandom

import org.scalajs.dom
import org.scalajs.dom.html.Input
import org.scalajs.dom.{UIEvent, document}
import rescala.core.ReSerializable
import rescala.restoration.{LocalStorageStore, ReCirce}
import rescala.restoration.ReCirce.{recirce, varDecoder, varEncoder}
import rescala.debuggable.ChromeDebuggerInterface
import rescalatags._
import scalatags.JsDom.all._
import scalatags.JsDom.tags2.section

import scala.scalajs.js.annotation.JSExportTopLevel

object Demo {

  implicit val storingEngine: LocalStorageStore = new LocalStorageStore()
  import storingEngine._

  implicit val taskDecoder: io.circe.Decoder[Task] = io.circe.Decoder.decodeTuple2[Var[String], Var[Boolean]].map { case (desc, done) =>
    new Task(desc, done)
  }
  implicit val taskEncoder: io.circe.Encoder[Task] = io.circe.Encoder.encodeTuple2[Var[String], Var[Boolean]].contramap{ t =>
    (t.desc, t.done)
  }

  class Task(val desc : Var[String], val done : Var[Boolean]) {
    val editing = Var(false)(ReSerializable.doNotSerialize, implicitly)
  }
  object Task {
    def apply(desc: String, done: Boolean) = {
      val rn = s"Task(${ThreadLocalRandom.current().nextLong().toHexString})"
      val descV = Var(desc)(implicitly, rn.toString)
      val doneV = Var(done)(implicitly, rn.toString + "b")
      storingEngine.registerSource(descV)
      storingEngine.registerSource(doneV)
      new Task(descV, doneV)
    }
  }

  @JSExportTopLevel("live.Demo.main")
  def main(): Unit = {
    ChromeDebuggerInterface.setup(storingEngine)

    val content = storingEngine.transaction(){ tx =>

      val temperature = Evt[Double]

      val filtered = temperature.filter(_ < 100).filter(_ >= -40)

      val history: Signal[Seq[Double]] = filtered.last(50)

      val aggregation: Signal[Seq[Double] => Double] = Signal({ x: Seq[Double] => x.sum / x.size })

      val aggregated = Signal {
        aggregation.value(history.value)
      }


      div(
        `class` := "todoapp",
        header(
          `class` := "header",
          h1("Temperatures")
        ),

        section(
          `class` := "main",
          `style` := Signal {if (history.value.isEmpty) "display:hidden" else ""},
          Signal.dynamic {
            ul(`class` := "todo-list",
               history().map { temp =>
                 li(`class` := "no-editing ",
                    div(
                      `class` := "view",<commit_msg>remove unused definitions<commit_after>package live

import java.util.concurrent.ThreadLocalRandom

import org.scalajs.dom
import org.scalajs.dom.html.Input
import org.scalajs.dom.{UIEvent, document}
import rescala.core.ReSerializable
import rescala.restoration.{LocalStorageStore, ReCirce}
import rescala.restoration.ReCirce.{recirce, varDecoder, varEncoder}
import rescala.debuggable.ChromeDebuggerInterface
import rescalatags._
import scalatags.JsDom.all._
import scalatags.JsDom.tags2.section

import scala.scalajs.js.annotation.JSExportTopLevel

object Demo {

  implicit val storingEngine: LocalStorageStore = new LocalStorageStore()
  import storingEngine._

  @JSExportTopLevel("live.Demo.main")
  def main(): Unit = {
    ChromeDebuggerInterface.setup(storingEngine)

    val content = storingEngine.transaction(){ tx =>

      val temperature = Evt[Double]

      val filtered = temperature.filter(_ < 100).filter(_ >= -40)

      val history: Signal[Seq[Double]] = filtered.last(50)

      val aggregation: Signal[Seq[Double] => Double] = Signal({ x: Seq[Double] => x.sum / x.size })

      val aggregated = Signal {
        aggregation.value(history.value)
      }

      div(
        `class` := "todoapp",
        header(
          `class` := "header",
          h1("Temperatures")
        ),

        section(
          `class` := "main",
          `style` := Signal {if (history.value.isEmpty) "display:hidden" else ""},
          Signal.dynamic {
            ul(`class` := "todo-list",
               history().map { temp =>
                 li(`class` := "no-editing ",
                    div(
                      `class` := "view",
{'fraction_non_alphanumeric': 0.12790697674418605, 'fraction_numerical': 0.0048449612403100775, 'mean_word_length': 2.9740134744947064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5878953', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1249, 'n_words': 257}