Skip to content

Commit

Permalink
#[cfg(feature = "render")] and yew::Renderer (#2498)
Browse files Browse the repository at this point in the history
* Bring changes to this branch.

* Bring changes to this branch.

* Add feature render and renderer.

* Bring changes to this branch.

* Migrate examples to Renderer.

* Satisfy no any render.

* Satisfy ssr.

* Satisfy feature render.

* Lint feature soundness.

* Suppress tests.

* Fix pr-flow, update docs.

* Add a notice.

* Adjust visibility.

* Correctly feature gate tests.

* make test scope available under feature render.

* Fix CI.

* Fix CI.

* Restore tests module to its original place as well.

* Make bundles crate private.

* Make most bundle APIs private.

* Adjust docs.

* Adjust debug implementation.

* Replace start_app with Renderer.

* Adjust documentation.

* Remove unused lint.

* Remove start_app from docs.

* DomBundle -> ReconcileTarget.

* Adjust documentation.

* Once render, now csr.

* Fix docs as well.
  • Loading branch information
futursolo authored Mar 19, 2022
1 parent 3ad4540 commit 8bc2212
Show file tree
Hide file tree
Showing 99 changed files with 1,457 additions and 1,080 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/main-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ jobs:
command: clippy
args: --all-targets -- -D warnings

- name: Lint feature soundness
run: |
cargo clippy -- --deny=warnings
cargo clippy --features=ssr -- --deny=warnings
cargo clippy --features=csr -- --deny=warnings
cargo clippy --all-features --all-targets -- --deny=warnings
working-directory: packages/yew


clippy-release:
name: Clippy on release profile
Expand All @@ -49,6 +57,14 @@ jobs:
command: clippy
args: --all-targets --release -- -D warnings

- name: Lint feature soundness
run: |
cargo clippy --release -- --deny=warnings
cargo clippy --release --features=ssr -- --deny=warnings
cargo clippy --release --features=csr -- --deny=warnings
cargo clippy --release --all-features --all-targets -- --deny=warnings
working-directory: packages/yew


doc_tests:
name: Documentation Tests
Expand Down Expand Up @@ -180,4 +196,3 @@ jobs:
with:
command: test
args: -p yew-macro test_html_lints --features lints

2 changes: 1 addition & 1 deletion examples/agents/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ license = "MIT OR Apache-2.0"
log = "0.4"
serde = { version = "1.0", features = ["derive"] }
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
yew-agent = { path = "../../packages/yew-agent" }
gloo-timers = "0.2"
2 changes: 1 addition & 1 deletion examples/agents/src/bin/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fn main() {
wasm_logger::init(wasm_logger::Config::default());
yew::start_app::<agents::App>();
yew::Renderer::<agents::App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/boids/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ anyhow = "1.0"
getrandom = { version = "0.2", features = ["js"] }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo = "0.6"

[dependencies.web-sys]
Expand Down
2 changes: 1 addition & 1 deletion examples/boids/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,5 @@ impl App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/contexts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ license = "MIT OR Apache-2.0"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
yew-agent = { path = "../../packages/yew-agent" }
2 changes: 1 addition & 1 deletion examples/contexts/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ pub fn App() -> Html {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ license = "MIT OR Apache-2.0"
[dependencies]
gloo-console = "0.2"
js-sys = "0.3"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
wasm-bindgen = "0.2"
2 changes: 1 addition & 1 deletion examples/counter/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ impl Component for App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/dyn_create_destroy_apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
js-sys = "0.3"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
slab = "0.4.3"
gloo = "0.6"
wasm-bindgen = "0.2"
Expand Down
7 changes: 4 additions & 3 deletions examples/dyn_create_destroy_apps/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ impl Component for App {
// Get the key for the entry and create and mount a new CounterModel app
// with a callback that destroys the app when emitted
let app_key = app_entry.key();
let new_counter_app = yew::start_app_with_props_in_element(
let new_counter_app = yew::Renderer::<CounterModel>::with_root_and_props(
app_div.clone(),
CounterProps {
destroy_callback: ctx
.link()
.callback(move |_| Msg::DestroyCounterApp(app_key)),
},
);
)
.render();

// Insert the app and the app div to our app collection
app_entry.insert((app_div, new_counter_app));
Expand Down Expand Up @@ -107,5 +108,5 @@ impl Component for App {

fn main() {
// Start main app
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/file_upload/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
js-sys = "0.3"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo-file = "0.2"

[dependencies.web-sys]
Expand Down
2 changes: 1 addition & 1 deletion examples/file_upload/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ impl App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/function_memory_game/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ gloo = "0.6"
nanoid = "0.4"
rand = "0.8"
getrandom = { version = "0.2", features = ["js"] }
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }

[dependencies.web-sys]
version = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/function_memory_game/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ mod state;
use crate::components::app::App;

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
3 changes: 3 additions & 0 deletions examples/function_router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ wasm-logger = "0.2"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
instant = { version = "0.1" }

[features]
csr = ["yew/csr"]
1 change: 1 addition & 0 deletions examples/function_router/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css"
/>
<link data-trunk rel="sass" href="index.scss" />
<link data-trunk rel="rust" data-cargo-features="csr" />
</head>

<body></body>
Expand Down
3 changes: 2 additions & 1 deletion examples/function_router/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ pub use app::*;
fn main() {
#[cfg(target_arch = "wasm32")]
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
yew::start_app::<App>();
#[cfg(feature = "render")]
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/function_todomvc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde = { version = "1.0", features = ["derive"] }
strum = "0.24"
strum_macros = "0.24"
gloo = "0.6"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }

[dependencies.web-sys]
version = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/function_todomvc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,5 +145,5 @@ fn app() -> Html {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "MIT OR Apache-2.0"
pulldown-cmark = { version = "0.9", default-features = false }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
yew = { path = "../../packages/yew", features = ["tokio"] }
yew = { path = "../../packages/yew", features = ["tokio", "csr"] }
gloo-utils = "0.1"

[dependencies.web-sys]
Expand Down
2 changes: 1 addition & 1 deletion examples/futures/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ impl Component for App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/game_of_life/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ getrandom = { version = "0.2", features = ["js"] }
log = "0.4"
rand = "0.8"
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo-timers = "0.2"
2 changes: 1 addition & 1 deletion examples/game_of_life/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,5 +226,5 @@ fn wrap(coord: isize, range: isize) -> usize {
fn main() {
wasm_logger::init(wasm_logger::Config::default());
log::trace!("Initializing yew...");
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/inner_html/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo-utils = "0.1"

[dependencies.web-sys]
Expand Down
2 changes: 1 addition & 1 deletion examples/inner_html/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ impl Component for App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/js_callback/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
wasm-bindgen = "0.2"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }

[dependencies.web-sys]
version = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/js_callback/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ impl Component for App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/keyed_list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ instant = { version = "0.1", features = ["wasm-bindgen"] }
log = "0.4"
rand = "0.8"
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }

[dependencies.web-sys]
version = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion examples/keyed_list/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,5 +279,5 @@ impl App {

fn main() {
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/mount_point/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"

[dependencies]
wasm-bindgen = "0.2"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo-utils = "0.1"

[dependencies.web-sys]
Expand Down
2 changes: 1 addition & 1 deletion examples/mount_point/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ fn main() {

body.append_child(&mount_point).unwrap();

yew::start_app_in_element::<App>(mount_point);
yew::Renderer::<App>::with_root(mount_point).render();
}
2 changes: 1 addition & 1 deletion examples/nested_list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ license = "MIT OR Apache-2.0"
[dependencies]
log = "0.4"
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
2 changes: 1 addition & 1 deletion examples/nested_list/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ impl fmt::Display for Hovered {

fn main() {
wasm_logger::init(wasm_logger::Config::default());
yew::start_app::<app::App>();
yew::Renderer::<app::App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/node_refs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
web-sys = { version = "0.3", features = ["HtmlElement", "HtmlInputElement", "Node"] }
2 changes: 1 addition & 1 deletion examples/node_refs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ impl Component for App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/password_strength/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
zxcvbn = "2.1.2, <2.2.0"
js-sys = "0.3.46"
web-sys = { version = "0.3", features = ["Event","EventTarget","InputEvent"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/password_strength/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ mod password;
use app::App;

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/portals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
gloo-utils = "0.1"
wasm-bindgen = "0.2"

Expand Down
2 changes: 1 addition & 1 deletion examples/portals/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ impl Component for App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ log = "0.4"
getrandom = { version = "0.2", features = ["js"] }
rand = { version = "0.8", features = ["small_rng"] }
wasm-logger = "0.2"
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
yew-router = { path = "../../packages/yew-router" }
serde = { version = "1.0", features = ["derive"] }
lazy_static = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/router/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,5 @@ fn switch(routes: &Route) -> Html {

fn main() {
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/suspense/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yew = { path = "../../packages/yew", features = ["tokio"] }
yew = { path = "../../packages/yew", features = ["tokio", "csr"] }
gloo-timers = { version = "0.2.2", features = ["futures"] }
wasm-bindgen-futures = "0.4"
wasm-bindgen = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion examples/suspense/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ fn app() -> Html {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
2 changes: 1 addition & 1 deletion examples/timer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
license = "MIT OR Apache-2.0"

[dependencies]
yew = { path = "../../packages/yew" }
yew = { path = "../../packages/yew", features = ["csr"] }
js-sys = "0.3"
gloo = "0.6"
wasm-bindgen = "0.2"
2 changes: 1 addition & 1 deletion examples/timer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,5 +150,5 @@ impl Component for App {
}

fn main() {
yew::start_app::<App>();
yew::Renderer::<App>::new().render();
}
Loading

1 comment on commit 8bc2212

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yew master branch benchmarks (Lower is better)

Benchmark suite Current: 8bc2212 Previous: 3ad4540 Ratio
yew-struct-keyed 01_run1k 185.2795 173.0935 1.07
yew-struct-keyed 02_replace1k 199.5645 193.954 1.03
yew-struct-keyed 03_update10th1k_x16 379.8255 380.7005 1.00
yew-struct-keyed 04_select1k 74.57400000000001 84.451 0.88
yew-struct-keyed 05_swap1k 102.6335 105.99 0.97
yew-struct-keyed 06_remove-one-1k 32.038 32.082 1.00
yew-struct-keyed 07_create10k 2279.255 2077.3805 1.10
yew-struct-keyed 08_create1k-after1k_x2 431.4185 387.118 1.11
yew-struct-keyed 09_clear1k_x8 212.28 204.399 1.04
yew-struct-keyed 21_ready-memory 0.9634475708007812 0.9634475708007812 1
yew-struct-keyed 22_run-memory 1.45648193359375 1.5028305053710938 0.97
yew-struct-keyed 23_update5-memory 1.4602203369140625 1.5026588439941406 0.97
yew-struct-keyed 24_run5-memory 1.5052261352539062 1.5052261352539062 1
yew-struct-keyed 25_run-clear-memory 1.1240730285644531 1.1237678527832031 1.00
yew-struct-keyed 31_startup-ci 1732.364 1732.208 1.00
yew-struct-keyed 32_startup-bt 33.02199999999999 29.835999999999984 1.11
yew-struct-keyed 34_startup-totalbytes 330.5498046875 330.5498046875 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.