mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Document features automatically. (#2780)
* document features automatically. * Document with `#[cfg(...)]`. * Fix Clippy. * Adjust unreleased docs header. * Adapt dark mode as well.
This commit is contained in:
parent
423ef28afe
commit
6f53a4e677
@ -1,4 +1,4 @@
|
||||
<div id="unreleased-version-header">
|
||||
<p>This is unreleased documentation for Yew Next version.</p>
|
||||
<p>For up-to-date documentation, see <a href="https://docs.rs/yew">the latest version on docs.rs</a>.</p>
|
||||
<div>This is unreleased documentation for Yew Next version.</div>
|
||||
<div>For up-to-date documentation, see <a href="https://docs.rs/yew">the latest version on docs.rs</a>.</div>
|
||||
</div>
|
||||
|
||||
@ -1,13 +1,23 @@
|
||||
#unreleased-version-header {
|
||||
background-color: rgb(77, 56, 0);
|
||||
background-color: rgb(200, 237, 248);
|
||||
z-index: 400;
|
||||
position: fixed;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
right: 0;
|
||||
height: 70px;
|
||||
padding-top: 10px;
|
||||
padding-bottom: 10px;
|
||||
text-align: center;
|
||||
font-family: sans-serif;
|
||||
box-shadow: 0 0 5px 0 rgb(100, 100, 100);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
#unreleased-version-header {
|
||||
background-color: rgb(32, 43, 57);
|
||||
box-shadow: 0 0 5px 0 black;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
|
||||
@ -9,7 +9,7 @@ use crate::dom_bundle::BSubtree;
|
||||
use crate::html::{BaseComponent, NodeRef, Scope, Scoped};
|
||||
|
||||
/// An instance of an application.
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "csr")))]
|
||||
#[cfg(feature = "csr")]
|
||||
#[derive(Debug)]
|
||||
pub struct AppHandle<COMP: BaseComponent> {
|
||||
/// `Scope` holder
|
||||
@ -65,7 +65,6 @@ fn clear_element(host: &Element) {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "hydration")))]
|
||||
#[cfg(feature = "hydration")]
|
||||
mod feat_hydration {
|
||||
use super::*;
|
||||
|
||||
@ -232,7 +232,7 @@ static BUBBLE_EVENTS: AtomicBool = AtomicBool::new(true);
|
||||
/// handler has no effect.
|
||||
///
|
||||
/// This function should be called before any component is mounted.
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "csr")))]
|
||||
#[cfg(feature = "csr")]
|
||||
pub fn set_event_bubbling(bubble: bool) {
|
||||
BUBBLE_EVENTS.store(bubble, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
@ -3,14 +3,10 @@ mod use_context;
|
||||
mod use_effect;
|
||||
mod use_force_update;
|
||||
mod use_memo;
|
||||
#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))]
|
||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
||||
mod use_prepared_state;
|
||||
mod use_reducer;
|
||||
mod use_ref;
|
||||
mod use_state;
|
||||
#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))]
|
||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
||||
mod use_transitive_state;
|
||||
|
||||
pub use use_callback::*;
|
||||
@ -18,14 +14,10 @@ pub use use_context::*;
|
||||
pub use use_effect::*;
|
||||
pub use use_force_update::*;
|
||||
pub use use_memo::*;
|
||||
#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))]
|
||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
||||
pub use use_prepared_state::*;
|
||||
pub use use_reducer::*;
|
||||
pub use use_ref::*;
|
||||
pub use use_state::*;
|
||||
#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))]
|
||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
||||
pub use use_transitive_state::*;
|
||||
|
||||
use crate::functional::HookContext;
|
||||
|
||||
@ -89,7 +89,6 @@ pub use feat_ssr::*;
|
||||
/// Whilst async closure is an unstable feature, the procedural macro will rewrite this to a
|
||||
/// closure that returns an async block automatically. You can use this hook with async closure
|
||||
/// in stable Rust.
|
||||
#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))]
|
||||
pub use use_prepared_state_macro as use_prepared_state;
|
||||
// With SSR.
|
||||
#[doc(hidden)]
|
||||
|
||||
@ -55,7 +55,6 @@ pub use feat_ssr::*;
|
||||
/// You MUST denote the return type of the closure with `|deps| -> ReturnType { ... }`. This
|
||||
/// type is used during client side rendering to deserialize the state prepared on the server
|
||||
/// side.
|
||||
#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))]
|
||||
pub use use_transitive_state_macro as use_transitive_state;
|
||||
// With SSR.
|
||||
#[doc(hidden)]
|
||||
|
||||
@ -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};
|
||||
@ -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")]
|
||||
@ -83,7 +81,6 @@ 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,
|
||||
@ -91,14 +88,11 @@ pub struct HookContext {
|
||||
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,
|
||||
|
||||
@ -111,29 +105,22 @@ 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 {
|
||||
@ -141,7 +128,6 @@ impl HookContext {
|
||||
None => Vec::new(),
|
||||
}
|
||||
},
|
||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
||||
#[cfg(feature = "hydration")]
|
||||
prepared_state_counter: 0,
|
||||
|
||||
@ -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,
|
||||
@ -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;
|
||||
@ -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() {
|
||||
@ -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(),
|
||||
),
|
||||
|
||||
@ -609,7 +609,6 @@ mod feat_csr {
|
||||
#[cfg(feature = "csr")]
|
||||
pub(crate) use feat_csr::*;
|
||||
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "hydration")))]
|
||||
#[cfg(feature = "hydration")]
|
||||
mod feat_hydration {
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
#![allow(clippy::needless_doctest_main)]
|
||||
#![doc(html_logo_url = "https://yew.rs/img/logo.png")]
|
||||
#![cfg_attr(documenting, feature(doc_cfg))]
|
||||
#![cfg_attr(documenting, feature(doc_auto_cfg))]
|
||||
#![cfg_attr(
|
||||
feature = "nightly",
|
||||
feature(fn_traits, async_closure, unboxed_closures)
|
||||
|
||||
@ -14,7 +14,7 @@ thread_local! {
|
||||
/// Set a custom panic hook.
|
||||
/// Unless a panic hook is set through this function, Yew will
|
||||
/// overwrite any existing panic hook when an application is rendered with [Renderer].
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "csr")))]
|
||||
#[cfg(feature = "csr")]
|
||||
pub fn set_custom_panic_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + Sync + Send + 'static>) {
|
||||
std::panic::set_hook(hook);
|
||||
PANIC_HOOK_IS_SET.with(|hook_is_set| hook_is_set.set(true));
|
||||
@ -29,7 +29,7 @@ fn set_default_panic_hook() {
|
||||
/// The Yew Renderer.
|
||||
///
|
||||
/// This is the main entry point of a Yew application.
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "csr")))]
|
||||
#[cfg(feature = "csr")]
|
||||
#[derive(Debug)]
|
||||
#[must_use = "Renderer does nothing unless render() is called."]
|
||||
pub struct Renderer<COMP>
|
||||
@ -93,7 +93,6 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "hydration")))]
|
||||
#[cfg(feature = "hydration")]
|
||||
mod feat_hydration {
|
||||
use super::*;
|
||||
|
||||
@ -7,7 +7,7 @@ use crate::platform::io::{self, DEFAULT_BUF_SIZE};
|
||||
use crate::platform::{run_pinned, spawn_local};
|
||||
|
||||
/// A Yew Server-side Renderer that renders on the current thread.
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "ssr")))]
|
||||
#[cfg(feature = "ssr")]
|
||||
#[derive(Debug)]
|
||||
pub struct LocalServerRenderer<COMP>
|
||||
where
|
||||
@ -112,7 +112,7 @@ where
|
||||
/// the rendering process has finished.
|
||||
///
|
||||
/// See [`yew::platform`] for more information.
|
||||
#[cfg_attr(documenting, doc(cfg(feature = "ssr")))]
|
||||
#[cfg(feature = "ssr")]
|
||||
pub struct ServerRenderer<COMP>
|
||||
where
|
||||
COMP: BaseComponent,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user