Skip to content

Commit

Permalink
add spair::set_arm!()
Browse files Browse the repository at this point in the history
  • Loading branch information
aclueless committed Jul 24, 2021
1 parent 85662d6 commit 7cb4cb8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
9 changes: 3 additions & 6 deletions examples/components/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ impl spair::Component for State {
.nodes()
.p(|p| {
p.r#static("The value that read from the child-component: ")
.match_if(|arm| match self.value_read_from_child {
Some(value) => arm.render_on_arm_index(line!()).render(value).done(),
None => arm
.render_on_arm_index(line!())
.render("[Not read yet]")
.done(),
.match_if(|mi| match self.value_read_from_child {
Some(value) => spair::set_arm!(mi).render(value).done(),
None => spair::set_arm!(mi).render("[Not read yet]").done(),
});
})
.r#static(Button("-", comp.handler_mut(State::decrement)))
Expand Down
8 changes: 3 additions & 5 deletions examples/fetch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ impl spair::Component for State {
fn render(&self, element: spair::Element<Self>) {
let comp = element.comp();
element
.match_if(|arm| match self.branch.as_ref() {
Some(branch) => arm
.render_on_arm_index(line!())
.match_if(|mi| match self.branch.as_ref() {
Some(branch) => spair::set_arm!(mi)
.render(branch)
.button(|b| {
b.static_attributes()
Expand All @@ -81,8 +80,7 @@ impl spair::Component for State {
.r#static("Reset");
})
.done(),
None => arm
.render_on_arm_index(line!())
None => spair::set_arm!(mi)
.button(|b| {
b.static_attributes()
.on_click(comp.handler_mut(State::start_fetching))
Expand Down
9 changes: 3 additions & 6 deletions examples/todomvc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,9 @@ impl spair::ListItemRender<App> for &TodoItem {
.class("destroy");
});
})
.match_if(|arm| match is_editing_me {
true => arm
.render_on_arm_index(line!())
.render(EditingInput(&self.title))
.done(),
false => arm.render_on_arm_index(line!()).done(),
.match_if(|mi| match is_editing_me {
true => spair::set_arm!(mi).render(EditingInput(&self.title)).done(),
false => spair::set_arm!(mi).done(),
});
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod component;
mod dom;
mod events;
mod fetch;
mod macros;
mod routing;
mod utils;

Expand Down
6 changes: 6 additions & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[macro_export]
macro_rules! set_arm {
( $match_if:ident ) => {
$match_if.render_on_arm_index(line!())
};
}

0 comments on commit 7cb4cb8

Please sign in to comment.