Skip to content

Commit

Permalink
Merge #589
Browse files Browse the repository at this point in the history
589: Allow components to accept children elements r=jstarry a=jstarry

Fixes: #537

#### Terminology
- (B) Base component that renders components nested inside each other
- (P) Parent component that has a `children` property and can render those children
- (C) Child component that is nested inside parent and included inside the Parent's `children`

#### Todo
- [x] Add example for nested components
- [x] Support arbitrary html nested inside component tags
- [x] Support nested components inside component tags
- [x] Allow modifying & accessing (C) props when rendering (P)
- [x] Allow filtering (C) components when rendering (P)
- [x] Children prop be required or optional
- [x] Clean up nested component example
- [x] Fix parser for generic component type
- [x] Write tests
- [x] Update documentation and README
- [x] ~~Investigate passing required properties from (P) -> (C)~~
- [x] ~~Allow sending messages from (C) -> (B)~~


Co-authored-by: Justin Starry <jstarry@users.noreply.github.com>
  • Loading branch information
bors[bot] and jstarry committed Sep 10, 2019
2 parents c627946 + 429ab73 commit 24d39f9
Show file tree
Hide file tree
Showing 24 changed files with 1,188 additions and 195 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ members = [
"examples/minimal",
"examples/mount_point",
"examples/multi_thread",
"examples/nested_list",
"examples/npm_and_rest",
"examples/routing",
"examples/server",
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ html! {
<nav class="menu">
<MyButton title="First Button" />
<MyButton title="Second Button "/>
<MyList name="Grocery List">
<MyListItem text="Apples" />
</MyList>
</nav>
}
```
Expand Down
20 changes: 18 additions & 2 deletions crates/macro/src/derive_props/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,29 @@ impl TryFrom<Field> for PropField {

impl PartialOrd for PropField {
fn partial_cmp(&self, other: &PropField) -> Option<Ordering> {
self.name.partial_cmp(&other.name)
if self.name == other.name {
Some(Ordering::Equal)
} else if self.name == "children" {
Some(Ordering::Greater)
} else if other.name == "children" {
Some(Ordering::Less)
} else {
self.name.partial_cmp(&other.name)
}
}
}

impl Ord for PropField {
fn cmp(&self, other: &PropField) -> Ordering {
self.name.cmp(&other.name)
if self.name == other.name {
Ordering::Equal
} else if self.name == "children" {
Ordering::Greater
} else if other.name == "children" {
Ordering::Less
} else {
self.name.cmp(&other.name)
}
}
}

Expand Down
Loading

0 comments on commit 24d39f9

Please sign in to comment.