Skip to content

Commit

Permalink
rework a bunch of feature flags to be more principled
Browse files Browse the repository at this point in the history
  • Loading branch information
WorldSEnder committed May 7, 2022
1 parent 64e2582 commit 5a2ef78
Show file tree
Hide file tree
Showing 48 changed files with 482 additions and 493 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: -p yew --doc --features doc_test --target wasm32-unknown-unknown
args: -p yew --doc --features csr,hydration,ssr --target wasm32-unknown-unknown

integration_tests:
name: Integration Tests on ${{ matrix.toolchain }}
Expand Down Expand Up @@ -159,8 +159,8 @@ jobs:
- name: Run tests - yew
run: |
cd packages/yew
CHROMEDRIVER=$(which chromedriver) cargo test --features wasm_test --target wasm32-unknown-unknown
GECKODRIVER=$(which geckodriver) cargo test --features wasm_test --target wasm32-unknown-unknown
CHROMEDRIVER=$(which chromedriver) cargo test --features csr,hydration,ssr --target wasm32-unknown-unknown
GECKODRIVER=$(which geckodriver) cargo test --features csr,hydration,ssr --target wasm32-unknown-unknown
- name: Run tests - yew-router
run: |
Expand Down
2 changes: 2 additions & 0 deletions examples/function_router/src/bin/function_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ fn main() {
wasm_logger::init(wasm_logger::Config::new(log::Level::Trace));
#[cfg(feature = "csr")]
yew::Renderer::<App>::new().render();
#[cfg(not(feature = "csr"))]
panic!("You must enable the csr feature to run this binary");
}
2 changes: 1 addition & 1 deletion examples/ssr_router/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", features = ["ssr", "hydration", "trace_hydration"] }
yew = { path = "../../packages/yew", features = ["ssr", "hydration"] }
function_router = { path = "../function_router" }
log = "0.4"

Expand Down
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", "csr"] }
yew = { path = "../../packages/yew", features = ["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 @@ -26,7 +26,7 @@ fn app_content() -> HtmlResult {
})
};

let on_take_a_break = Callback::from(move |_| (resleep.clone())());
let on_take_a_break = Callback::from(move |_| resleep());

Ok(html! {
<div class="content-area">
Expand Down
1 change: 0 additions & 1 deletion packages/yew-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ yew = { path = "../yew" }
[build-dependencies]

[features]
doc_test = []
lints = []
3 changes: 0 additions & 3 deletions packages/yew-router/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ description = "A router implementation for the Yew framework"
repository = "https://github.com/yewstack/yew"
rust-version = "1.56.0"

[features]
wasm_test = []

[dependencies]
yew = { version = "0.19.3", path = "../yew", default-features= false }
yew-router-macro = { version = "0.16.0", path = "../yew-router-macro" }
Expand Down
5 changes: 1 addition & 4 deletions packages/yew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,11 @@ features = [
ssr = ["futures", "html-escape"]
csr = []
hydration = ["csr"]
trace_hydration = ["hydration"]
doc_test = ["csr", "hydration", "ssr"]
wasm_test = ["csr", "hydration", "ssr"]
default = []

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
tokio = { version = "1.15.0", features = ["full"] }

[package.metadata.docs.rs]
features = ["doc_test"]
features = ["csr", "hydration", "ssr"]
rustdoc-args = ["--cfg", "documenting"]
3 changes: 2 additions & 1 deletion packages/yew/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ args = [
"--headless",
"--",
"--features",
"wasm_test"
"csr,hydration,ssr"
]

[tasks.ssr-test]
command = "cargo"
args = ["test", "ssr_tests", "--features", "ssr"]

[tasks.test]
args = ["test", "--all-targets", "--all-features"]
dependencies = ["native-test", "wasm-test"]

[tasks.clippy-feature-soundness]
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/app_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::dom_bundle::BSubtree;
use crate::html::{BaseComponent, NodeRef, Scope, Scoped};

/// An instance of an application.
#[derive(Debug)]
#[cfg_attr(documenting, doc(cfg(feature = "csr")))]
#[derive(Debug)]
pub struct AppHandle<COMP: BaseComponent> {
/// `Scope` holder
pub(crate) scope: Scope<COMP>,
Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/bcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ mod feat_hydration {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod tests {
use std::ops::Deref;
Expand Down Expand Up @@ -481,7 +481,7 @@ mod tests {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;
Expand Down
8 changes: 4 additions & 4 deletions packages/yew/src/dom_bundle/blist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,11 @@ mod feat_hydration {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use crate::html;
Expand Down Expand Up @@ -581,11 +581,11 @@ mod layout_tests {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests_keys {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use web_sys::Node;

Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/bnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ mod feat_hydration {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use super::*;
Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/bportal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ impl BPortal {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use yew::virtual_dom::VPortal;

Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/btag/listeners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ impl Registry {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod tests {
use std::marker::PhantomData;
Expand Down
12 changes: 6 additions & 6 deletions packages/yew/src/dom_bundle/btag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ impl BTag {
self.key.as_ref()
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
fn reference(&self) -> &Element {
&self.reference
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
fn children(&self) -> &[BNode] {
match &self.inner {
Expand All @@ -280,7 +280,7 @@ impl BTag {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
fn tag(&self) -> &str {
match &self.inner {
Expand Down Expand Up @@ -383,7 +383,7 @@ mod feat_hydration {
}
}

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod tests {
use gloo_utils::document;
Expand Down Expand Up @@ -975,11 +975,11 @@ mod tests {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use crate::html;
Expand Down
8 changes: 4 additions & 4 deletions packages/yew/src/dom_bundle/btext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ mod feat_hydration {
mod test {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use crate::html;

#[cfg(feature = "wasm_test")]
#[cfg(target_arch = "wasm32")]
wasm_bindgen_test_configure!(run_in_browser);

#[test]
Expand All @@ -177,11 +177,11 @@ mod test {
}
}

#[cfg(all(test, feature = "wasm_test"))]
#[cfg(target_arch = "wasm32")]
#[cfg(test)]
mod layout_tests {
extern crate self as yew;

#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};

use crate::html;
Expand Down
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::ops::{Deref, DerefMut};

use web_sys::{Element, Node};

use super::BSubtree;
use crate::dom_bundle::BSubtree;
use crate::html::NodeRef;
use crate::virtual_dom::Collectable;

/// A Hydration Fragment
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub(crate) struct Fragment(VecDeque<Node>);
pub struct Fragment(VecDeque<Node>);

impl Deref for Fragment {
type Target = VecDeque<Node>;
Expand Down
51 changes: 25 additions & 26 deletions packages/yew/src/dom_bundle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ mod btag;
mod btext;
mod subtree_root;

#[cfg(feature = "hydration")]
mod fragment;

mod traits;
mod utils;

Expand All @@ -32,18 +29,24 @@ use bportal::BPortal;
use bsuspense::BSuspense;
use btag::{BTag, Registry};
use btext::BText;
#[cfg(feature = "hydration")]
pub(crate) use fragment::Fragment;
pub use subtree_root::set_event_bubbling;
pub(crate) use subtree_root::BSubtree;
use subtree_root::EventDescriptor;
#[cfg(feature = "hydration")]
use traits::Hydratable;
pub use subtree_root::{set_event_bubbling, BSubtree};
use traits::{Reconcilable, ReconcileTarget};
#[cfg(feature = "hydration")]
use utils::node_type_str;
use utils::{insert_node, test_log};

#[cfg(feature = "hydration")]
#[path = "."]
mod feat_hydration {
#[path = "./fragment.rs"]
mod fragment;
pub use fragment::Fragment;

pub(super) use super::traits::Hydratable;
pub(super) use super::utils::node_type_str;
}
#[cfg(feature = "hydration")]
pub(crate) use feat_hydration::*;

/// A Bundle.
///
/// Each component holds a bundle that represents a realised layout, designated by a [VNode].
Expand Down Expand Up @@ -84,20 +87,16 @@ impl Bundle {
}

#[cfg(feature = "hydration")]
mod feat_hydration {
use super::*;

impl Bundle {
/// Creates a bundle by hydrating a virtual dom layout.
pub fn hydrate(
root: &BSubtree,
parent_scope: &AnyScope,
parent: &Element,
fragment: &mut Fragment,
node: VNode,
) -> (NodeRef, Self) {
let (node_ref, bundle) = node.hydrate(root, parent_scope, parent, fragment);
(node_ref, Self(bundle))
}
impl Bundle {
/// Creates a bundle by hydrating a virtual dom layout.
pub fn hydrate(
root: &BSubtree,
parent_scope: &AnyScope,
parent: &Element,
fragment: &mut Fragment,
node: VNode,
) -> (NodeRef, Self) {
let (node_ref, bundle) = node.hydrate(root, parent_scope, parent, fragment);
(node_ref, Self(bundle))
}
}
4 changes: 2 additions & 2 deletions packages/yew/src/dom_bundle/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ pub(super) fn insert_node(node: &Node, parent: &Element, next_sibling: Option<&N
};
}

#[cfg(all(test, feature = "wasm_test", verbose_tests))]
#[cfg(all(test, target_arch = "wasm32", verbose_tests))]
macro_rules! test_log {
($fmt:literal, $($arg:expr),* $(,)?) => {
::wasm_bindgen_test::console_log!(concat!("\t ", $fmt), $($arg),*);
};
}
#[cfg(not(all(test, feature = "wasm_test", verbose_tests)))]
#[cfg(not(all(test, target_arch = "wasm32", verbose_tests)))]
macro_rules! test_log {
($fmt:literal, $($arg:expr),* $(,)?) => {
// Only type-check the format expression, do not run any side effects
Expand Down

0 comments on commit 5a2ef78

Please sign in to comment.