Skip to content

Instantly share code, notes, and snippets.

@pjazdzewski1990
Created September 30, 2015 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjazdzewski1990/a23d3988759aa8b32ca7 to your computer and use it in GitHub Desktop.
Save pjazdzewski1990/a23d3988759aa8b32ca7 to your computer and use it in GitHub Desktop.
@JSExport
def main(target: html.Div): Unit = {
...
/// create a chain of reactive variables
val mouseVar = everyClick(addButton)
val addTodo = Obs(mouseVar) {
val desc = addDesc.value
val time = Try{ addTime.value.toInt }.toOption.getOrElse(0)
println(s"Adding $desc/$time")
addNewTodo(desc, time)
}
val timeVar = everySecond()
val todoTimeCount = Rx {
thingsToDo().foldLeft(0)((x, y) => x + y.time)
}
val todoCount = Rx {
thingsToDo().length
}
val updateTimeSummary = Rx {
refreshTimeSummary(timeVar(), todoTimeCount())
}
val updateTimeSummaryStyle = Rx {
val count = todoCount()
if(count >= 5) {
timeSummary.style.backgroundColor = Color.Red
} else {
timeSummary.style.backgroundColor = Color.White
}
}
val updateTodoList = Rx {
refreshTodoList(target, thingsToDo())
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment