diff --git a/readme.md b/readme.md index e6977d2..f84f802 100644 --- a/readme.md +++ b/readme.md @@ -8,8 +8,8 @@ Dependencies: -* [kotlinx-html-js](https://github.com/Kotlin/kotlinx.html) -* [komponent](https://github.com/rnentjes/komponent) +* [kotlinx-html](https://github.com/Kotlin/kotlinx.html) +* [kotlin-komponent](https://github.com/rnentjes/komponent) This is the complete source: @@ -32,7 +32,7 @@ * see: https://github.com/tastejs/todomvc/ */ -class Todo( +data class Todo( val dataId: String, var title: String, var completed: Boolean = false, @@ -105,7 +105,7 @@ if (target is HTMLInputElement) { todoList.add(Todo("${Date().getTime()}", target.value)) - requestUpdate() + this@TodoApp.requestUpdate() } } @@ -133,7 +133,7 @@ requestUpdate() } - fun clearCompleted() { + fun clearCompleted(e: Event) { for (todo in ArrayList(todoList)) { if (todo.completed) { todoList.remove(todo) @@ -149,15 +149,7 @@ requestUpdate() } - fun getItemsLeft(): Int { - var result = 0 - for (todo in todoList) { - if (!todo.completed) { - result++ - } - } - return result - } + private fun getItemsLeft(): Int = todoList.count { todo -> !todo.completed } fun setEditing(editTodo: Todo) { for (todo in todoList) { @@ -215,8 +207,16 @@ footer(classes = "footer") { span(classes = "todo-count") { - strong { +"${getItemsLeft()}" } - +" item left" + when(getItemsLeft()) { + 0 -> { + + "No items" + } + 1 -> { + + "1 item left" + } + else -> + + "${getItemsLeft()} items left" + } } ul(classes = "filters") { for (selection in Selection.values()) { @@ -236,9 +236,7 @@ } button(classes = "clear-completed") { +"Clear completed" - onClickFunction = { - clearCompleted() - } + onClickFunction = ::clearCompleted } } }