Skip to content

Commit 339cdbd

Browse files
committed
todo: remove nesting
1 parent b82f595 commit 339cdbd

1 file changed

Lines changed: 16 additions & 25 deletions

File tree

examples/todo/main.mbt

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -208,33 +208,24 @@ fn main {
208208
list.set_text_content("")
209209
next_id = 0
210210

211-
match storage.get_item(storage_key) {
212-
Some(raw) =>
213-
if raw != "" {
214-
for encoded in raw.split(entry_sep) {
215-
if !encoded.is_empty() {
216-
match encoded.find(field_sep) {
217-
Some(split_idx) => {
218-
let done_flag = encoded.view(end_offset=split_idx).to_string()
219-
let text = encoded
220-
.view(start_offset=split_idx + 1)
221-
.to_string()
222-
if text != "" {
223-
let done = done_flag == "1"
224-
let todo_id = next_id
225-
next_id = next_id + 1
226-
todos.push((todo_id, done, text))
227-
append_todo_to_dom(todo_id, done, text)
228-
}
229-
}
230-
None => ()
231-
}
232-
}
233-
}
211+
guard storage.get_item(storage_key) is Some(raw) else { return }
212+
213+
if raw != "" {
214+
for encoded in raw.split(entry_sep) {
215+
guard !encoded.is_empty() && encoded.find(field_sep) is Some(split_idx) else {
216+
continue
217+
}
218+
let done_flag = encoded.view(end_offset=split_idx).to_string()
219+
let text = encoded.view(start_offset=split_idx + 1).to_string()
220+
if text != "" {
221+
let done = done_flag == "1"
222+
let todo_id = next_id
223+
next_id = next_id + 1
224+
todos.push((todo_id, done, text))
225+
append_todo_to_dom(todo_id, done, text)
234226
}
235-
None => ()
227+
}
236228
}
237-
238229
update_status()
239230
}
240231

0 commit comments

Comments
 (0)