Skip to content

Commit b5dcd2f

Browse files
committed
Move function router into a separate binary.
1 parent bfef5d3 commit b5dcd2f

File tree

6 files changed

+40
-58
lines changed

6 files changed

+40
-58
lines changed

examples/function_router/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,11 @@ yew-router = { path = "../../packages/yew-router" }
1313
serde = { version = "1.0", features = ["derive"] }
1414
lazy_static = "1.4.0"
1515
gloo-timers = "0.2"
16+
wasm-logger = "0.2"
17+
instant = { version = "0.1", features = ["wasm-bindgen"] }
1618

1719
[target.'cfg(target_arch = "wasm32")'.dependencies]
1820
getrandom = { version = "0.2", features = ["js"] }
19-
instant = { version = "0.1", features = ["wasm-bindgen"] }
20-
wasm-logger = "0.2"
21-
22-
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
23-
instant = { version = "0.1" }
2421

2522
[features]
2623
csr = ["yew/csr"]

examples/function_router/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"
1212
/>
1313
<link data-trunk rel="sass" href="index.scss" />
14-
<link data-trunk rel="rust" data-cargo-features="csr" />
14+
<link data-trunk rel="rust" data-cargo-features="csr" data-bin="function_router" />
1515
</head>
1616

1717
<body></body>

examples/function_router/src/app.rs

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
use std::collections::HashMap;
2+
13
use yew::prelude::*;
4+
use yew::virtual_dom::AttrValue;
5+
use yew_router::history::{AnyHistory, History, MemoryHistory};
26
use yew_router::prelude::*;
37

48
use crate::components::nav::Nav;
@@ -47,53 +51,40 @@ pub fn App() -> Html {
4751
}
4852
}
4953

50-
#[cfg(not(target_arch = "wasm32"))]
51-
mod arch_native {
52-
use super::*;
53-
54-
use yew::virtual_dom::AttrValue;
55-
use yew_router::history::{AnyHistory, History, MemoryHistory};
56-
57-
use std::collections::HashMap;
58-
59-
#[derive(Properties, PartialEq, Debug)]
60-
pub struct ServerAppProps {
61-
pub url: AttrValue,
62-
pub queries: HashMap<String, String>,
63-
}
54+
#[derive(Properties, PartialEq, Debug)]
55+
pub struct ServerAppProps {
56+
pub url: AttrValue,
57+
pub queries: HashMap<String, String>,
58+
}
6459

65-
#[function_component]
66-
pub fn ServerApp(props: &ServerAppProps) -> Html {
67-
let history = AnyHistory::from(MemoryHistory::new());
68-
history
69-
.push_with_query(&*props.url, &props.queries)
70-
.unwrap();
60+
#[function_component]
61+
pub fn ServerApp(props: &ServerAppProps) -> Html {
62+
let history = AnyHistory::from(MemoryHistory::new());
63+
history
64+
.push_with_query(&*props.url, &props.queries)
65+
.unwrap();
7166

72-
html! {
73-
<Router history={history}>
74-
<Nav />
67+
html! {
68+
<Router history={history}>
69+
<Nav />
7570

76-
<main>
77-
<Switch<Route> render={Switch::render(switch)} />
78-
</main>
79-
<footer class="footer">
80-
<div class="content has-text-centered">
81-
{ "Powered by " }
82-
<a href="https://yew.rs">{ "Yew" }</a>
83-
{ " using " }
84-
<a href="https://bulma.io">{ "Bulma" }</a>
85-
{ " and images from " }
86-
<a href="https://unsplash.com">{ "Unsplash" }</a>
87-
</div>
88-
</footer>
89-
</Router>
90-
}
71+
<main>
72+
<Switch<Route> render={Switch::render(switch)} />
73+
</main>
74+
<footer class="footer">
75+
<div class="content has-text-centered">
76+
{ "Powered by " }
77+
<a href="https://yew.rs">{ "Yew" }</a>
78+
{ " using " }
79+
<a href="https://bulma.io">{ "Bulma" }</a>
80+
{ " and images from " }
81+
<a href="https://unsplash.com">{ "Unsplash" }</a>
82+
</div>
83+
</footer>
84+
</Router>
9185
}
9286
}
9387

94-
#[cfg(not(target_arch = "wasm32"))]
95-
pub use arch_native::*;
96-
9788
fn switch(routes: &Route) -> Html {
9889
match routes.clone() {
9990
Route::Post { id } => {

examples/function_router/src/main.rs renamed to examples/function_router/src/bin/function_router.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
mod app;
2-
mod components;
3-
mod content;
4-
mod generator;
5-
mod pages;
6-
7-
pub use app::*;
1+
pub use function_router::*;
82

93
fn main() {
10-
#[cfg(target_arch = "wasm32")]
114
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
125
#[cfg(feature = "csr")]
136
yew::Renderer::<App>::new().render();

examples/simple_ssr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ log = "0.4"
1919
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
2020
tokio = { version = "1.15.0", features = ["full"] }
2121
warp = "0.3"
22-
structopt = "0.3"
2322
num_cpus = "1.13"
2423
tokio-util = { version = "0.7", features = ["rt"] }
2524
once_cell = "1.5"
25+
clap = { version = "3.1.7", features = ["derive"] }

examples/simple_ssr/src/bin/simple_ssr_server.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use clap::Parser;
12
use once_cell::sync::Lazy;
23
use simple_ssr::App;
34
use std::path::PathBuf;
@@ -9,7 +10,7 @@ use warp::Filter;
910
static LOCAL_POOL: Lazy<LocalPoolHandle> = Lazy::new(|| LocalPoolHandle::new(num_cpus::get()));
1011

1112
/// A basic example
12-
#[derive(StructOpt, Debug)]
13+
#[derive(Parser, Debug)]
1314
struct Opt {
1415
/// the "dist" created by trunk directory to be served for hydration.
1516
#[structopt(short, long, parse(from_os_str))]
@@ -33,7 +34,7 @@ async fn render(index_html_s: &str) -> String {
3334

3435
#[tokio::main]
3536
async fn main() {
36-
let opts = Opt::from_args();
37+
let opts = Opt::parse();
3738

3839
let index_html_s = tokio::fs::read_to_string(opts.dir.join("index.html"))
3940
.await

0 commit comments

Comments
 (0)