-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for struct instance properties
- Loading branch information
1 parent
19515cc
commit e22b0ec
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#[macro_use] | ||
extern crate yew; | ||
|
||
use yew::html::{Component, Env, Html, Renderable, ShouldRender}; | ||
use yew::virtual_dom::VNode; | ||
|
||
type Ctx = (); | ||
|
||
struct Comp; | ||
|
||
#[derive(PartialEq, Clone)] | ||
struct Props { | ||
field_1: u32, | ||
field_2: u32, | ||
} | ||
|
||
impl Default for Props { | ||
fn default() -> Self { | ||
Props { | ||
field_1: 0, | ||
field_2: 0, | ||
} | ||
} | ||
} | ||
|
||
impl Component<Ctx> for Comp { | ||
type Message = (); | ||
type Properties = Props; | ||
|
||
fn create(_: Self::Properties, _: &mut Env<Ctx, Self>) -> Self { | ||
Comp | ||
} | ||
|
||
fn update(&mut self, _: Self::Message, _: &mut Env<Ctx, Self>) -> ShouldRender { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
impl Renderable<Ctx, Comp> for Comp { | ||
fn view(&self) -> Html<Ctx, Self> { | ||
unimplemented!(); | ||
} | ||
} | ||
|
||
#[test] | ||
fn set_properties_to_component() { | ||
let _: VNode<Ctx, Comp> = html! { | ||
<Comp: /> | ||
}; | ||
|
||
let _: VNode<Ctx, Comp> = html! { | ||
<Comp: field_1=1, /> | ||
}; | ||
|
||
let _: VNode<Ctx, Comp> = html! { | ||
<Comp: field_2=2, /> | ||
}; | ||
|
||
let _: VNode<Ctx, Comp> = html! { | ||
<Comp: field_1=1, field_2=2, /> | ||
}; | ||
|
||
let props = Props { | ||
field_1: 1, | ||
field_2: 1, | ||
}; | ||
|
||
let _: VNode<Ctx, Comp> = html! { | ||
<Comp: with props, field_2=2, /> | ||
}; | ||
} |