Update readme
This commit is contained in:
36
readme.md
36
readme.md
@@ -8,8 +8,8 @@ You can also find an example of a complete application here: [simple-password-ma
|
||||
|
||||
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 @@ import kotlin.js.Date
|
||||
* 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 @@ class TodoApp : Komponent() {
|
||||
if (target is HTMLInputElement) {
|
||||
todoList.add(Todo("${Date().getTime()}", target.value))
|
||||
|
||||
requestUpdate()
|
||||
this@TodoApp.requestUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ class TodoApp : Komponent() {
|
||||
requestUpdate()
|
||||
}
|
||||
|
||||
fun clearCompleted() {
|
||||
fun clearCompleted(e: Event) {
|
||||
for (todo in ArrayList(todoList)) {
|
||||
if (todo.completed) {
|
||||
todoList.remove(todo)
|
||||
@@ -149,15 +149,7 @@ class TodoApp : Komponent() {
|
||||
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 @@ class TodoApp : Komponent() {
|
||||
|
||||
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 @@ class TodoApp : Komponent() {
|
||||
}
|
||||
button(classes = "clear-completed") {
|
||||
+"Clear completed"
|
||||
onClickFunction = {
|
||||
clearCompleted()
|
||||
}
|
||||
onClickFunction = ::clearCompleted
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user