Update readme

This commit is contained in:
2024-01-24 17:29:35 +01:00
parent 722da6dd81
commit 1a6b07fa11

View File

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