package com.campudus.scycle

import org.scalajs.dom
import rx._

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

@JSExport
object TutorialApp extends JSApp {

  @JSExport
  def main(): Unit = {
    val i = Var(0)
    val text = Rx {
      s"Seconds elapsed ${i()}"
    }

    dom.setInterval(() => {
      i() = i() + 1
      dom.console.log(text())
    }, 1000)

    dom.document.getElementById("app").textContent = text()
  }

}



package com.campudus.scycle

import org.scalajs.dom
import rx._

import scala.scalajs.js.JSApp
import scala.scalajs.js.annotation.JSExport

@JSExport
object TutorialApp extends JSApp {

  @JSExport
  def main(): Unit = {
    val container = dom.document.getElementById("app")
    val i = Var(0)
    val text = Rx {
      s"Seconds elapsed ${i()}"
    }

    val iObserver = Obs(text) {
      container.textContent = text()
    }

    dom.setInterval(() => {
      i() = i() + 1
    }, 1000)
  }

}



Use Obs to observe text changes and write them into the DOM
Use Obs to observe text changes and write them into the DOM

Signed-off-by: Joern Bernhardt <7b85a41a628204b76aba4326273a3ccc74bd009a@campudus.com>
