package com.campudus.scycle

import com.campudus.scycle.Scycle._
import com.campudus.scycle.dom._
import rxscalajs._

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

@JSExport
object ScycleApp extends JSApp {

  @JSExport
  def main(): Unit = {
    println("main export")

    Scycle.run(logic, drivers)
  }

  val drivers: DriversDefinition = Map[String, DriverFunction[_, _]](
    "dom" -> new DomDriver
  )

  def logic(drivers: Sources): Sinks = {
    println(s"ScycleApp.logic($drivers)")
    val domDriver$ = drivers("dom").asInstanceOf[Subject[DomDriver]]
    val clicks$ = domDriver$.flatMap(driver => driver.selectEvent("#app", "click"))
    var counter = 0

    Map(
      "dom" -> {
        Observable.just(null)/*.concat(clicks$)*/.map(_ => {
          counter += 1
          Div(id = "app", children = Seq(Text(s"hello from scycle - clicks=$counter")))
        })
      }
    )
  }

}

package com.campudus.scycle

import com.campudus.scycle.Scycle._
import com.campudus.scycle.dom._
import rxscalajs._

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

@JSExport
object ScycleApp extends JSApp {

  @JSExport
  def main(): Unit = {
    println("main export")

    Scycle.run(logic, drivers)
  }

  val drivers: DriversDefinition = Map[String, DriverFunction[_, _]](
    "dom" -> new DomDriver
  )

  def logic(drivers: Sources): Sinks = {
    println(s"ScycleApp.logic($drivers)")
    Map(
      "dom" -> {
        Observable.just(Div(id = "app", children = Seq(Text("hello from scycle"))))
      }
    )
  }

}

--- 
+++ 
@@ -23,9 +23,16 @@
 
   def logic(drivers: Sources): Sinks = {
     println(s"ScycleApp.logic($drivers)")
+    val domDriver$ = drivers("dom").asInstanceOf[Subject[DomDriver]]
+    val clicks$ = domDriver$.flatMap(driver => driver.selectEvent("#app", "click"))
+    var counter = 0
+
     Map(
       "dom" -> {
-        Observable.just(Div(id = "app", children = Seq(Text("hello from scycle"))))
+        Observable.just(null)/*.concat(clicks$)*/.map(_ => {
+          counter += 1
+          Div(id = "app", children = Seq(Text(s"hello from scycle - clicks=$counter")))
+        })
       }
     )
   }
Modify simple app to use an observable from driver - does not work yet

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