Skip to content

Commit

Permalink
Minor tweaks to remove panic branches in TodoMVC (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejhirsz authored Apr 13, 2024
1 parent 3e2121c commit f422e60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/todomvc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"esbuild": "^0.14.47"
"esbuild": "^0.20.2"
},
"scripts": {
"minify": "mv ./dist/kobold_todomvc_example.js ./dist/kobold_todomvc_example_large.js && esbuild --bundle ./dist/kobold_todomvc_example_large.js --outfile=./dist/kobold_todomvc_example.js --minify --format=esm"
Expand Down
20 changes: 11 additions & 9 deletions examples/todomvc/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ impl State {
if let Some(entry) = self.editing.and_then(|idx| self.entries.get_mut(idx)) {
entry.editing = false;
}

self.editing = Some(idx);
self.entries[idx].editing = true;

self.store();
if let Some(entry) = self.entries.get_mut(idx) {
self.editing = Some(idx);
entry.editing = true;
}
}

pub fn add(&mut self, description: String) {
Expand All @@ -142,7 +141,9 @@ impl State {
}

pub fn update(&mut self, idx: usize, description: String) {
let entry = &mut self.entries[idx];
let Some(entry) = self.entries.get_mut(idx) else {
return;
};

entry.editing = false;

Expand All @@ -153,9 +154,10 @@ impl State {
}

pub fn toggle(&mut self, idx: usize) {
self.entries[idx].completed ^= true;

self.store();
if let Some(entry) = self.entries.get_mut(idx) {
entry.completed ^= true;
self.store();
}
}
}

Expand Down

0 comments on commit f422e60

Please sign in to comment.