diff --git a/examples/showcase/Cargo.toml b/examples/showcase/Cargo.toml index 41974dd90..82a008bbb 100644 --- a/examples/showcase/Cargo.toml +++ b/examples/showcase/Cargo.toml @@ -9,3 +9,4 @@ counter = { path = "sub/counter" } crm = { path = "sub/crm" } custom_components = { path = "sub/custom_components" } dashboard = { path = "sub/dashboard" } +fragments = { path = "sub/fragments" } diff --git a/examples/showcase/src/main.rs b/examples/showcase/src/main.rs index 8e0dbeddf..be1f5baf3 100644 --- a/examples/showcase/src/main.rs +++ b/examples/showcase/src/main.rs @@ -4,6 +4,7 @@ extern crate counter; extern crate crm; extern crate custom_components; extern crate dashboard; +extern crate fragments; use yew::prelude::*; use yew::services::console::ConsoleService; @@ -15,6 +16,7 @@ use counter::Model as Counter; use crm::Model as Crm; use custom_components::Model as CustomComponents; use dashboard::Model as Dashboard; +use fragments::Model as Fragments; struct Context { console: ConsoleService, @@ -66,6 +68,7 @@ enum Scene { Crm, CustomComponents, Dashboard, + Fragments, } enum Msg { @@ -99,6 +102,7 @@ impl Renderable for Scene { + { self.view_scene() } } } @@ -132,6 +136,11 @@ impl Scene { } } + Scene::Fragments => { + html! { + + } + } } } } diff --git a/examples/showcase/sub/fragments/Cargo.toml b/examples/showcase/sub/fragments/Cargo.toml index 32cd11d6b..2232c23e5 100644 --- a/examples/showcase/sub/fragments/Cargo.toml +++ b/examples/showcase/sub/fragments/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" authors = ["Denis Kolodin "] [dependencies] -yew = { path = "../.." } +yew = { path = "../../../.." } diff --git a/examples/showcase/sub/fragments/src/lib.rs b/examples/showcase/sub/fragments/src/lib.rs new file mode 100644 index 000000000..1099d4d3d --- /dev/null +++ b/examples/showcase/sub/fragments/src/lib.rs @@ -0,0 +1,86 @@ +#[macro_use] +extern crate yew; + +use yew::prelude::*; + +pub struct Model { + counter: usize, +} + +pub enum Msg { + More, + Less, +} + +impl Component for Model { + type Msg = Msg; + type Properties = (); + + fn create(_: Self::Properties, _: &mut Env) -> Self { + Model { + counter: 0, + } + } + + fn update(&mut self, msg: Self::Msg, _: &mut Env) -> ShouldRender { + match msg { + Msg::More => { + self.counter = self.counter + 1; + } + Msg::Less => { + if self.counter > 0 { + self.counter = self.counter - 1; + } + } + } + true + } +} + +impl Renderable for Model +where + CTX: 'static, +{ + fn view(&self) -> Html { + html! { + <> + + + + { self.view_cols() } + { self.view_cols() } + { self.view_cols() } + +
+ + } + } +} + +impl Model { + fn view_cols(&self) -> Html + where + CTX: 'static, + { + let render = |idx| html! { + { idx } + }; + html! { + <> + { for (0..self.counter).map(render) } + + } + } + + fn view_menu(&self) -> Html + where + CTX: 'static, + { + html! { + <> + + + + } + } +} diff --git a/examples/showcase/sub/fragments/src/main.rs b/examples/showcase/sub/fragments/src/main.rs index 5bfd7566d..9529e364d 100644 --- a/examples/showcase/sub/fragments/src/main.rs +++ b/examples/showcase/sub/fragments/src/main.rs @@ -1,82 +1,8 @@ -#[macro_use] extern crate yew; +extern crate fragments; use yew::prelude::*; - -type Context = (); - -struct Model { - counter: usize, -} - -enum Msg { - More, - Less, -} - -impl Component for Model { - type Msg = Msg; - type Properties = (); - - fn create(_: Self::Properties, _: &mut Env) -> Self { - Model { - counter: 0, - } - } - - fn update(&mut self, msg: Self::Msg, _: &mut Env) -> ShouldRender { - match msg { - Msg::More => { - self.counter = self.counter + 1; - } - Msg::Less => { - if self.counter > 0 { - self.counter = self.counter - 1; - } - } - } - true - } -} - -impl Renderable for Model { - fn view(&self) -> Html { - html! { - <> - - - - { self.view_cols() } - { self.view_cols() } - { self.view_cols() } - -
- - } - } -} - -impl Model { - fn view_cols(&self) -> Html { - let render = |idx| html! { - { idx } - }; - html! { - <> - { for (0..self.counter).map(render) } - - } - } - - fn view_menu(&self) -> Html { - html! { - <> - - - - } - } -} +use fragments::Model; fn main() { yew::initialize();