forked from yewstack/yew
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make virtual dom cloneable (yewstack#786)
- Loading branch information
Showing
31 changed files
with
274 additions
and
176 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
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
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
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 |
---|---|---|
|
@@ -5,4 +5,6 @@ authors = ["Justin Starry <[email protected]>"] | |
edition = "2018" | ||
|
||
[dependencies] | ||
log = "0.4" | ||
web_logger = "0.2" | ||
yew = { path = "../.." } |
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,77 @@ | ||
use super::header::ListHeader; | ||
use super::item::ListItem; | ||
use super::list::List; | ||
use super::{Hovered, WeakComponentLink}; | ||
use yew::prelude::*; | ||
|
||
pub struct App { | ||
link: ComponentLink<Self>, | ||
hovered: Hovered, | ||
} | ||
|
||
pub enum Msg { | ||
Hover(Hovered), | ||
} | ||
|
||
impl Component for App { | ||
type Message = Msg; | ||
type Properties = (); | ||
|
||
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self { | ||
App { | ||
link, | ||
hovered: Hovered::None, | ||
} | ||
} | ||
|
||
fn update(&mut self, msg: Self::Message) -> ShouldRender { | ||
match msg { | ||
Msg::Hover(hovered) => self.hovered = hovered, | ||
} | ||
true | ||
} | ||
|
||
fn view(&self) -> Html { | ||
let on_hover = &self.link.callback(Msg::Hover); | ||
let onmouseenter = &self.link.callback(|_| Msg::Hover(Hovered::None)); | ||
let list_link = &WeakComponentLink::<List>::default(); | ||
let sub_list_link = &WeakComponentLink::<List>::default(); | ||
html! { | ||
<div class="main" onmouseenter=onmouseenter> | ||
<h1>{ "Nested List Demo" }</h1> | ||
<List on_hover=on_hover weak_link=list_link> | ||
<ListHeader text="Calling all Rusties!" on_hover=on_hover list_link=list_link /> | ||
<ListItem name="Rustin" on_hover=on_hover /> | ||
<ListItem hide={true} name="Rustaroo" on_hover=on_hover /> | ||
<ListItem name="Rustifer" on_hover=on_hover> | ||
<div class="sublist">{"Sublist!"}</div> | ||
{ | ||
html! { | ||
<List on_hover=on_hover weak_link=sub_list_link> | ||
<ListHeader text="Sub Rusties!" on_hover=on_hover list_link=sub_list_link/> | ||
<ListItem name="Sub Rustin" on_hover=on_hover /> | ||
<ListItem hide={true} name="Sub Rustaroo" on_hover=on_hover /> | ||
<ListItem name="Sub Rustifer" on_hover=on_hover /> | ||
</List> | ||
} | ||
} | ||
</ListItem> | ||
</List> | ||
{self.view_last_hovered()} | ||
</div> | ||
} | ||
} | ||
} | ||
|
||
impl App { | ||
fn view_last_hovered(&self) -> Html { | ||
html! { | ||
<div class="last-hovered"> | ||
{ "Last hovered:"} | ||
<span class="last-hovered-text"> | ||
{ &self.hovered } | ||
</span> | ||
</div> | ||
} | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
fn main() { | ||
yew::start_app::<nested_list::Model>(); | ||
web_logger::init(); | ||
yew::start_app::<nested_list::App>(); | ||
} |
Oops, something went wrong.