Last active
September 25, 2016 18:01
-
-
Save LukaJCB/decf8b3a987b475893b58cb9dfdba6ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val nameStream = createInputHandler() | |
val component = div( | |
label(className := "label", "Name:"), | |
input(inputType := "text", input --> nameStream), | |
hr(), | |
h1("Hello ", child <-- nameStream) | |
) | |
render(document.getElementById("app"), component) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class Person(firstName: String, lastName: String) | |
def PersonComponent(person: Person, hideStream: Subject[Person]) = | |
div( | |
span(s"${person.firstName} ${person.lastName}"), | |
button(click(person) --> hideStream, "delete") | |
) | |
val person = Person("Luka", "J") | |
val hideStream = createHandler[Person]() | |
val personHidden = hideStream.mapTo(true).startWith(false) | |
val component = div( | |
h1("Headline"), | |
div(hidden <-- personHidden, | |
PersonComponent(person, hideStream) | |
) | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val plusClicked = createEventHandler() | |
val minusClicked = createEventHandler() | |
val plusStream = plusClicked.mapTo(1) | |
val minusStream = minusClicked.mapTo(-1) | |
val state = plusStream.merge(minusStream) | |
.scan((previousState, increment) => previousState + increment) | |
.startWith(0) | |
val component = div( | |
button(click --> plusClicked, "+"), | |
button(click --> minusClicked, "-"), | |
hr(), | |
h1(child <-- state) | |
) | |
render(document.getElementById("app"), component) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val textInput = createInputHandler() | |
val requests = textInput | |
.debounceTime(400) | |
.filter(_.length > 2) | |
.map(query => s"api/users/$query") | |
val responses = Http.get(requests) | |
.map(_.name) | |
val component = div( | |
input(inputType := "text", change --> textInput), | |
hr(), | |
h1(child <-- responses) | |
) | |
render(document.getElementById("app"), component) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val nameStream = createInputHandler() | |
val clicks = createEventHandler() | |
val todos: Observable[Seq[VNode]] = clicks.withLatestFrom(nameStream) | |
.map(_._2) | |
.scan(List[String]())((acc, cur) => acc +: cur) | |
.map(_.map(todo => li(todo)) | |
div( | |
label(className := "label", "Name:"), | |
input(inputType := "text", input --> nameStream), | |
button("Add Todo", click --> clicks), | |
hr(), | |
ul(children <-- todos) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment