Skip to content

Commit 5cdca12

Browse files
author
Ryan Miville
committed
add type annotations
1 parent d8e5f7c commit 5cdca12

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/todomvc.gleam

+19-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import gleam/order
77
import lustre
88
import lustre/attribute.{type Attribute}
99
import lustre/effect.{type Effect}
10-
import lustre/element
10+
import lustre/element.{type Element}
1111
import lustre/element/html
1212
import lustre/event
1313

@@ -158,7 +158,7 @@ fn update(model: Model, msg: Msg) -> #(Model, Effect(Msg)) {
158158

159159
// VIEW -----------------------------------------------------------------------
160160

161-
fn view(model: Model) {
161+
fn view(model: Model) -> Element(Msg) {
162162
html.div([], [
163163
html.div([attribute.class("todoapp")], [
164164
header(model),
@@ -169,14 +169,14 @@ fn view(model: Model) {
169169
])
170170
}
171171

172-
fn header(model: Model) {
172+
fn header(model: Model) -> Element(Msg) {
173173
html.header([attribute.class("header")], [
174174
html.h1([], [html.text("todos")]),
175175
new_todo(model),
176176
])
177177
}
178178

179-
fn main_content(model: Model) {
179+
fn main_content(model: Model) -> Element(Msg) {
180180
let visible_todos = case model.filter {
181181
All ->
182182
dict.values(model.todos)
@@ -197,7 +197,7 @@ fn main_content(model: Model) {
197197
])
198198
}
199199

200-
fn footer(model: Model) {
200+
fn footer(model: Model) -> Element(Msg) {
201201
let active_count =
202202
dict.values(model.todos)
203203
|> list.count(fn(i) { !i.completed })
@@ -208,7 +208,7 @@ fn footer(model: Model) {
208208
])
209209
}
210210

211-
fn new_todo(model: Model) {
211+
fn new_todo(model: Model) -> Element(Msg) {
212212
html.div([attribute.class("view")], [
213213
input(
214214
on_enter: on_enter(UserAddedTodo),
@@ -222,7 +222,7 @@ fn new_todo(model: Model) {
222222
])
223223
}
224224

225-
fn toggle(visible_todos: List(Todo)) {
225+
fn toggle(visible_todos: List(Todo)) -> Element(Msg) {
226226
use <- bool.guard(list.is_empty(visible_todos), element.none())
227227

228228
html.div([attribute.class("toggle-all-container")], [
@@ -239,12 +239,12 @@ fn toggle(visible_todos: List(Todo)) {
239239
])
240240
}
241241

242-
fn todo_list(visible_todos: List(Todo), model: Model) {
242+
fn todo_list(visible_todos: List(Todo), model: Model) -> Element(Msg) {
243243
let items = list.map(visible_todos, todo_item(_, model))
244244
html.ul([attribute.class("todo-list")], items)
245245
}
246246

247-
fn todo_item(item: Todo, model: Model) {
247+
fn todo_item(item: Todo, model: Model) -> Element(Msg) {
248248
let cn = case item.completed {
249249
True -> "completed"
250250
False -> ""
@@ -258,7 +258,7 @@ fn todo_item(item: Todo, model: Model) {
258258
html.li([attribute.class(cn)], [el])
259259
}
260260

261-
fn todo_item_edit(item: Todo, model: Model) {
261+
fn todo_item_edit(item: Todo, model: Model) -> Element(Msg) {
262262
html.div([attribute.class("view")], [
263263
input(
264264
on_enter: on_enter(UserEditedTodo(item.id)),
@@ -272,7 +272,7 @@ fn todo_item_edit(item: Todo, model: Model) {
272272
])
273273
}
274274

275-
fn todo_item_not_edit(item: Todo) {
275+
fn todo_item_not_edit(item: Todo) -> Element(Msg) {
276276
html.div([attribute.class("view")], [
277277
html.input([
278278
attribute.class("toggle"),
@@ -291,21 +291,21 @@ fn todo_item_not_edit(item: Todo) {
291291
])
292292
}
293293

294-
fn todo_count(count: Int) {
294+
fn todo_count(count: Int) -> Element(c) {
295295
let text = case count {
296296
1 -> "1 item left!"
297297
n -> int.to_string(n) <> " items left!"
298298
}
299299
html.span([attribute.class("todo-count")], [html.text(text)])
300300
}
301301

302-
fn filters(current: Filter) {
302+
fn filters(current: Filter) -> Element(Msg) {
303303
[All, Active, Completed]
304304
|> list.map(filter_item(_, current))
305305
|> html.ul([attribute.class("filters")], _)
306306
}
307307

308-
fn filter_item(item: Filter, current: Filter) {
308+
fn filter_item(item: Filter, current: Filter) -> Element(Msg) {
309309
let cn = case item == current {
310310
True -> "selected"
311311
False -> ""
@@ -323,7 +323,7 @@ fn filter_item(item: Filter, current: Filter) {
323323
])
324324
}
325325

326-
fn clear_completed(model: Model) {
326+
fn clear_completed(model: Model) -> Element(Msg) {
327327
let disabled = dict.is_empty(model.todos)
328328
html.button(
329329
[
@@ -343,7 +343,7 @@ fn input(
343343
autofocus autofocus: Bool,
344344
label label: String,
345345
value value: String,
346-
) {
346+
) -> Element(Msg) {
347347
html.div([attribute.class("input-container")], [
348348
html.input([
349349
attribute.class("new-todo"),
@@ -363,18 +363,18 @@ fn input(
363363
])
364364
}
365365

366-
fn edit_message() {
366+
fn edit_message() -> Element(b) {
367367
html.footer([attribute.class("info")], [
368368
html.p([], [html.text("Double-click to edit a todo")]),
369369
])
370370
}
371371

372-
fn delete_todo(id: Int) {
372+
fn delete_todo(id: Int) -> Effect(Msg) {
373373
use dispatch <- effect.from
374374
dispatch(UserDeletedTodo(id))
375375
}
376376

377-
fn on_double_click(msg: Msg) {
377+
fn on_double_click(msg: Msg) -> Attribute(Msg) {
378378
use _ <- event.on("dblclick")
379379
Ok(msg)
380380
}

0 commit comments

Comments
 (0)