Skip to content

Commit 444a8b6

Browse files
committed
rename onremove to ondestroy
1 parent 854c27b commit 444a8b6

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

examples/invoice/src/components/Cell.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn Cell(col: usize, row: usize, state: &Hook<State>) -> impl View + '_ {
2626
value = &"";
2727
}
2828

29-
let onremove_row = state.bind(move |state, event: MouseEvent<HtmlElement>| {
29+
let ondestroy_row = state.bind(move |state, event: MouseEvent<HtmlElement>| {
3030
let row = match event.target().get_attribute("data") {
3131
Some(r) => r,
3232
None => return,
@@ -36,7 +36,7 @@ pub fn Cell(col: usize, row: usize, state: &Hook<State>) -> impl View + '_ {
3636
Err(e) => return,
3737
};
3838

39-
state.remove_row_main(row_usize);
39+
state.destroy_row_main(row_usize);
4040
});
4141

4242
let onadd_row = state.bind(move |state, event: MouseEvent<HtmlElement>| {
@@ -91,7 +91,7 @@ pub fn Cell(col: usize, row: usize, state: &Hook<State>) -> impl View + '_ {
9191
<td.destroy-container>
9292
<button.destroy
9393
data={row}
94-
onclick={onremove_row}
94+
onclick={ondestroy_row}
9595
/>
9696
</td>
9797
})
@@ -126,7 +126,7 @@ pub fn Cell(col: usize, row: usize, state: &Hook<State>) -> impl View + '_ {
126126
<td.destroy-container>
127127
<button.destroy
128128
data={row}
129-
onclick={onremove_row}
129+
onclick={ondestroy_row}
130130
/>
131131
</td>
132132
})
@@ -148,7 +148,7 @@ pub fn Cell(col: usize, row: usize, state: &Hook<State>) -> impl View + '_ {
148148
<td.destroy-container>
149149
<button.destroy
150150
data={row}
151-
onclick={onremove_row}
151+
onclick={ondestroy_row}
152152
/>
153153
</td>
154154
})
@@ -163,3 +163,29 @@ pub fn Cell(col: usize, row: usize, state: &Hook<State>) -> impl View + '_ {
163163
}
164164
}
165165
}
166+
167+
// #[component(auto_branch)]
168+
// pub fn AddRow(
169+
// row: usize,
170+
// onadd_row_fn: &dyn Fn(&mut State, MouseEvent<HtmlElement>)
171+
// ) -> impl View {
172+
// view! {
173+
// <button.add
174+
// data={row}
175+
// onclick={onadd_row_fn}
176+
// />
177+
// }
178+
// }
179+
180+
// #[component(auto_branch)]
181+
// pub fn DestroyRow(
182+
// row: usize,
183+
// ondestroy_row_fn: &dyn Fn(&mut State, MouseEvent<HtmlElement>)
184+
// ) -> impl View {
185+
// view! {
186+
// <button.destroy
187+
// data={row}
188+
// onclick={ondestroy_row_fn}
189+
// />
190+
// }
191+
// }

examples/invoice/src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ impl State {
127127
//
128128
// Note: The code in this draft was not necessary
129129
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=53e5b5c0c241be2f5b37815a685e7da6
130-
pub fn remove_row_main(&mut self, row_idx_remove: usize) {
130+
pub fn destroy_row_main(&mut self, row_idx_destroy: usize) {
131131
// WARNING: do not remove the `source`, it must remain read-only
132132

133-
self.main.table.rows.remove(row_idx_remove); // remove from `rows`
133+
self.main.table.rows.remove(row_idx_destroy); // remove from `rows`
134134

135135
self.store();
136136
}

0 commit comments

Comments
 (0)