Skip to content

Commit

Permalink
Remove more feature flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
futursolo committed Jul 2, 2022
1 parent 8e43790 commit d01d478
Showing 1 changed file with 3 additions and 25 deletions.
28 changes: 3 additions & 25 deletions packages/yew/src/functional/mod.rs
Expand Up @@ -27,7 +27,6 @@ use std::rc::Rc;

use wasm_bindgen::prelude::*;

#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(all(feature = "hydration", feature = "ssr"))]
use crate::html::RenderMode;
use crate::html::{AnyScope, BaseComponent, Context, HtmlResult};
Expand Down Expand Up @@ -68,7 +67,6 @@ pub use yew_macro::hook;
type ReRender = Rc<dyn Fn()>;

/// Primitives of a prepared state hook.
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(any(feature = "hydration", feature = "ssr"))]
pub(crate) trait PreparedState {
#[cfg(feature = "ssr")]
Expand All @@ -83,22 +81,18 @@ pub(crate) trait Effect {
/// A hook context to be passed to hooks.
pub struct HookContext {
pub(crate) scope: AnyScope,
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(all(feature = "hydration", feature = "ssr"))]
creation_mode: RenderMode,
re_render: ReRender,

states: Vec<Rc<dyn Any>>,
effects: Vec<Rc<dyn Effect>>,

#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(any(feature = "hydration", feature = "ssr"))]
prepared_states: Vec<Rc<dyn PreparedState>>,

#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(feature = "hydration")]
prepared_states_data: Vec<Rc<str>>,
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(feature = "hydration")]
prepared_state_counter: usize,

Expand All @@ -111,37 +105,29 @@ impl HookContext {
fn new(
scope: AnyScope,
re_render: ReRender,
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(all(feature = "hydration", feature = "ssr"))]
creation_mode: RenderMode,
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(feature = "hydration")]
prepared_state: Option<&str>,
#[cfg(all(feature = "hydration", feature = "ssr"))] creation_mode: RenderMode,
#[cfg(feature = "hydration")] prepared_state: Option<&str>,
) -> RefCell<Self> {
RefCell::new(HookContext {
scope,
re_render,

#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(all(feature = "hydration", feature = "ssr"))]
creation_mode,

states: Vec::new(),

#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(any(feature = "hydration", feature = "ssr"))]
prepared_states: Vec::new(),
effects: Vec::new(),

#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(feature = "hydration")]
prepared_states_data: {
match prepared_state {
Some(m) => m.split(',').map(Rc::from).collect(),
None => Vec::new(),
}
},
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(feature = "hydration")]
prepared_state_counter: 0,

Expand Down Expand Up @@ -187,7 +173,6 @@ impl HookContext {
t
}

#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(any(feature = "hydration", feature = "ssr"))]
pub(crate) fn next_prepared_state<T>(
&mut self,
Expand Down Expand Up @@ -220,7 +205,6 @@ impl HookContext {

#[inline(always)]
fn prepare_run(&mut self) {
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(feature = "hydration")]
{
self.prepared_state_counter = 0;
Expand Down Expand Up @@ -277,15 +261,11 @@ impl HookContext {
}
}

#[cfg(any(
not(feature = "ssr"),
not(any(target_arch = "wasm32", feature = "tokio"))
))]
#[cfg(not(feature = "ssr"))]
fn prepare_state(&self) -> Option<String> {
None
}

#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(feature = "ssr")]
fn prepare_state(&self) -> Option<String> {
if self.prepared_states.is_empty() {
Expand Down Expand Up @@ -361,10 +341,8 @@ where
hook_ctx: HookContext::new(
scope,
re_render,
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(all(feature = "hydration", feature = "ssr"))]
ctx.creation_mode(),
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
#[cfg(feature = "hydration")]
ctx.prepared_state(),
),
Expand Down

0 comments on commit d01d478

Please sign in to comment.