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">
|
<div id="unreleased-version-header">
|
||||||
<p>This is unreleased documentation for Yew Next version.</p>
|
<div>This is unreleased documentation for Yew Next version.</div>
|
||||||
<p>For up-to-date documentation, see <a href="https://docs.rs/yew">the latest version on docs.rs</a>.</p>
|
<div>For up-to-date documentation, see <a href="https://docs.rs/yew">the latest version on docs.rs</a>.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,13 +1,23 @@
|
|||||||
#unreleased-version-header {
|
#unreleased-version-header {
|
||||||
background-color: rgb(77, 56, 0);
|
background-color: rgb(200, 237, 248);
|
||||||
z-index: 400;
|
z-index: 400;
|
||||||
position: fixed;
|
position: absolute;
|
||||||
left: 0;
|
left: 0;
|
||||||
top: 0;
|
top: 0;
|
||||||
right: 0;
|
right: 0;
|
||||||
height: 70px;
|
height: 70px;
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
|
padding-bottom: 10px;
|
||||||
text-align: center;
|
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 {
|
body {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ use crate::dom_bundle::BSubtree;
|
|||||||
use crate::html::{BaseComponent, NodeRef, Scope, Scoped};
|
use crate::html::{BaseComponent, NodeRef, Scope, Scoped};
|
||||||
|
|
||||||
/// An instance of an application.
|
/// An instance of an application.
|
||||||
#[cfg_attr(documenting, doc(cfg(feature = "csr")))]
|
#[cfg(feature = "csr")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct AppHandle<COMP: BaseComponent> {
|
pub struct AppHandle<COMP: BaseComponent> {
|
||||||
/// `Scope` holder
|
/// `Scope` holder
|
||||||
@ -65,7 +65,6 @@ fn clear_element(host: &Element) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(documenting, doc(cfg(feature = "hydration")))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
mod feat_hydration {
|
mod feat_hydration {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@ -232,7 +232,7 @@ static BUBBLE_EVENTS: AtomicBool = AtomicBool::new(true);
|
|||||||
/// handler has no effect.
|
/// handler has no effect.
|
||||||
///
|
///
|
||||||
/// This function should be called before any component is mounted.
|
/// 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) {
|
pub fn set_event_bubbling(bubble: bool) {
|
||||||
BUBBLE_EVENTS.store(bubble, Ordering::Relaxed);
|
BUBBLE_EVENTS.store(bubble, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,14 +3,10 @@ mod use_context;
|
|||||||
mod use_effect;
|
mod use_effect;
|
||||||
mod use_force_update;
|
mod use_force_update;
|
||||||
mod use_memo;
|
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_prepared_state;
|
||||||
mod use_reducer;
|
mod use_reducer;
|
||||||
mod use_ref;
|
mod use_ref;
|
||||||
mod use_state;
|
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;
|
mod use_transitive_state;
|
||||||
|
|
||||||
pub use use_callback::*;
|
pub use use_callback::*;
|
||||||
@ -18,14 +14,10 @@ pub use use_context::*;
|
|||||||
pub use use_effect::*;
|
pub use use_effect::*;
|
||||||
pub use use_force_update::*;
|
pub use use_force_update::*;
|
||||||
pub use use_memo::*;
|
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_prepared_state::*;
|
||||||
pub use use_reducer::*;
|
pub use use_reducer::*;
|
||||||
pub use use_ref::*;
|
pub use use_ref::*;
|
||||||
pub use use_state::*;
|
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::*;
|
pub use use_transitive_state::*;
|
||||||
|
|
||||||
use crate::functional::HookContext;
|
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
|
/// 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
|
/// closure that returns an async block automatically. You can use this hook with async closure
|
||||||
/// in stable Rust.
|
/// in stable Rust.
|
||||||
#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))]
|
|
||||||
pub use use_prepared_state_macro as use_prepared_state;
|
pub use use_prepared_state_macro as use_prepared_state;
|
||||||
// With SSR.
|
// With SSR.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|||||||
@ -55,7 +55,6 @@ pub use feat_ssr::*;
|
|||||||
/// You MUST denote the return type of the closure with `|deps| -> ReturnType { ... }`. This
|
/// 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
|
/// type is used during client side rendering to deserialize the state prepared on the server
|
||||||
/// side.
|
/// side.
|
||||||
#[cfg_attr(documenting, doc(cfg(any(target_arch = "wasm32", feature = "tokio"))))]
|
|
||||||
pub use use_transitive_state_macro as use_transitive_state;
|
pub use use_transitive_state_macro as use_transitive_state;
|
||||||
// With SSR.
|
// With SSR.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
|
|||||||
@ -27,7 +27,6 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
||||||
use crate::html::RenderMode;
|
use crate::html::RenderMode;
|
||||||
use crate::html::{AnyScope, BaseComponent, Context, HtmlResult};
|
use crate::html::{AnyScope, BaseComponent, Context, HtmlResult};
|
||||||
@ -68,7 +67,6 @@ pub use yew_macro::hook;
|
|||||||
type ReRender = Rc<dyn Fn()>;
|
type ReRender = Rc<dyn Fn()>;
|
||||||
|
|
||||||
/// Primitives of a prepared state hook.
|
/// Primitives of a prepared state hook.
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(any(feature = "hydration", feature = "ssr"))]
|
#[cfg(any(feature = "hydration", feature = "ssr"))]
|
||||||
pub(crate) trait PreparedState {
|
pub(crate) trait PreparedState {
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
@ -83,7 +81,6 @@ pub(crate) trait Effect {
|
|||||||
/// A hook context to be passed to hooks.
|
/// A hook context to be passed to hooks.
|
||||||
pub struct HookContext {
|
pub struct HookContext {
|
||||||
pub(crate) scope: AnyScope,
|
pub(crate) scope: AnyScope,
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
||||||
creation_mode: RenderMode,
|
creation_mode: RenderMode,
|
||||||
re_render: ReRender,
|
re_render: ReRender,
|
||||||
@ -91,14 +88,11 @@ pub struct HookContext {
|
|||||||
states: Vec<Rc<dyn Any>>,
|
states: Vec<Rc<dyn Any>>,
|
||||||
effects: Vec<Rc<dyn Effect>>,
|
effects: Vec<Rc<dyn Effect>>,
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(any(feature = "hydration", feature = "ssr"))]
|
#[cfg(any(feature = "hydration", feature = "ssr"))]
|
||||||
prepared_states: Vec<Rc<dyn PreparedState>>,
|
prepared_states: Vec<Rc<dyn PreparedState>>,
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
prepared_states_data: Vec<Rc<str>>,
|
prepared_states_data: Vec<Rc<str>>,
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
prepared_state_counter: usize,
|
prepared_state_counter: usize,
|
||||||
|
|
||||||
@ -111,29 +105,22 @@ impl HookContext {
|
|||||||
fn new(
|
fn new(
|
||||||
scope: AnyScope,
|
scope: AnyScope,
|
||||||
re_render: ReRender,
|
re_render: ReRender,
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
#[cfg(all(feature = "hydration", feature = "ssr"))] creation_mode: RenderMode,
|
||||||
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
#[cfg(feature = "hydration")] prepared_state: Option<&str>,
|
||||||
creation_mode: RenderMode,
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(feature = "hydration")]
|
|
||||||
prepared_state: Option<&str>,
|
|
||||||
) -> RefCell<Self> {
|
) -> RefCell<Self> {
|
||||||
RefCell::new(HookContext {
|
RefCell::new(HookContext {
|
||||||
scope,
|
scope,
|
||||||
re_render,
|
re_render,
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
||||||
creation_mode,
|
creation_mode,
|
||||||
|
|
||||||
states: Vec::new(),
|
states: Vec::new(),
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(any(feature = "hydration", feature = "ssr"))]
|
#[cfg(any(feature = "hydration", feature = "ssr"))]
|
||||||
prepared_states: Vec::new(),
|
prepared_states: Vec::new(),
|
||||||
effects: Vec::new(),
|
effects: Vec::new(),
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
prepared_states_data: {
|
prepared_states_data: {
|
||||||
match prepared_state {
|
match prepared_state {
|
||||||
@ -141,7 +128,6 @@ impl HookContext {
|
|||||||
None => Vec::new(),
|
None => Vec::new(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
prepared_state_counter: 0,
|
prepared_state_counter: 0,
|
||||||
|
|
||||||
@ -187,7 +173,6 @@ impl HookContext {
|
|||||||
t
|
t
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(any(feature = "hydration", feature = "ssr"))]
|
#[cfg(any(feature = "hydration", feature = "ssr"))]
|
||||||
pub(crate) fn next_prepared_state<T>(
|
pub(crate) fn next_prepared_state<T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
@ -220,7 +205,6 @@ impl HookContext {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn prepare_run(&mut self) {
|
fn prepare_run(&mut self) {
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
{
|
{
|
||||||
self.prepared_state_counter = 0;
|
self.prepared_state_counter = 0;
|
||||||
@ -277,15 +261,11 @@ impl HookContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
#[cfg(not(feature = "ssr"))]
|
||||||
not(feature = "ssr"),
|
|
||||||
not(any(target_arch = "wasm32", feature = "tokio"))
|
|
||||||
))]
|
|
||||||
fn prepare_state(&self) -> Option<String> {
|
fn prepare_state(&self) -> Option<String> {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
fn prepare_state(&self) -> Option<String> {
|
fn prepare_state(&self) -> Option<String> {
|
||||||
if self.prepared_states.is_empty() {
|
if self.prepared_states.is_empty() {
|
||||||
@ -361,10 +341,8 @@ where
|
|||||||
hook_ctx: HookContext::new(
|
hook_ctx: HookContext::new(
|
||||||
scope,
|
scope,
|
||||||
re_render,
|
re_render,
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
#[cfg(all(feature = "hydration", feature = "ssr"))]
|
||||||
ctx.creation_mode(),
|
ctx.creation_mode(),
|
||||||
#[cfg(any(target_arch = "wasm32", feature = "tokio"))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
ctx.prepared_state(),
|
ctx.prepared_state(),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -609,7 +609,6 @@ mod feat_csr {
|
|||||||
#[cfg(feature = "csr")]
|
#[cfg(feature = "csr")]
|
||||||
pub(crate) use feat_csr::*;
|
pub(crate) use feat_csr::*;
|
||||||
|
|
||||||
#[cfg_attr(documenting, doc(cfg(feature = "hydration")))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
mod feat_hydration {
|
mod feat_hydration {
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#![allow(clippy::needless_doctest_main)]
|
#![allow(clippy::needless_doctest_main)]
|
||||||
#![doc(html_logo_url = "https://yew.rs/img/logo.png")]
|
#![doc(html_logo_url = "https://yew.rs/img/logo.png")]
|
||||||
#![cfg_attr(documenting, feature(doc_cfg))]
|
#![cfg_attr(documenting, feature(doc_cfg))]
|
||||||
|
#![cfg_attr(documenting, feature(doc_auto_cfg))]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
feature = "nightly",
|
feature = "nightly",
|
||||||
feature(fn_traits, async_closure, unboxed_closures)
|
feature(fn_traits, async_closure, unboxed_closures)
|
||||||
|
|||||||
@ -14,7 +14,7 @@ thread_local! {
|
|||||||
/// Set a custom panic hook.
|
/// Set a custom panic hook.
|
||||||
/// Unless a panic hook is set through this function, Yew will
|
/// Unless a panic hook is set through this function, Yew will
|
||||||
/// overwrite any existing panic hook when an application is rendered with [Renderer].
|
/// 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>) {
|
pub fn set_custom_panic_hook(hook: Box<dyn Fn(&PanicInfo<'_>) + Sync + Send + 'static>) {
|
||||||
std::panic::set_hook(hook);
|
std::panic::set_hook(hook);
|
||||||
PANIC_HOOK_IS_SET.with(|hook_is_set| hook_is_set.set(true));
|
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.
|
/// The Yew Renderer.
|
||||||
///
|
///
|
||||||
/// This is the main entry point of a Yew application.
|
/// This is the main entry point of a Yew application.
|
||||||
#[cfg_attr(documenting, doc(cfg(feature = "csr")))]
|
#[cfg(feature = "csr")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[must_use = "Renderer does nothing unless render() is called."]
|
#[must_use = "Renderer does nothing unless render() is called."]
|
||||||
pub struct Renderer<COMP>
|
pub struct Renderer<COMP>
|
||||||
@ -93,7 +93,6 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(documenting, doc(cfg(feature = "hydration")))]
|
|
||||||
#[cfg(feature = "hydration")]
|
#[cfg(feature = "hydration")]
|
||||||
mod feat_hydration {
|
mod feat_hydration {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|||||||
@ -7,7 +7,7 @@ use crate::platform::io::{self, DEFAULT_BUF_SIZE};
|
|||||||
use crate::platform::{run_pinned, spawn_local};
|
use crate::platform::{run_pinned, spawn_local};
|
||||||
|
|
||||||
/// A Yew Server-side Renderer that renders on the current thread.
|
/// A Yew Server-side Renderer that renders on the current thread.
|
||||||
#[cfg_attr(documenting, doc(cfg(feature = "ssr")))]
|
#[cfg(feature = "ssr")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct LocalServerRenderer<COMP>
|
pub struct LocalServerRenderer<COMP>
|
||||||
where
|
where
|
||||||
@ -112,7 +112,7 @@ where
|
|||||||
/// the rendering process has finished.
|
/// the rendering process has finished.
|
||||||
///
|
///
|
||||||
/// See [`yew::platform`] for more information.
|
/// See [`yew::platform`] for more information.
|
||||||
#[cfg_attr(documenting, doc(cfg(feature = "ssr")))]
|
#[cfg(feature = "ssr")]
|
||||||
pub struct ServerRenderer<COMP>
|
pub struct ServerRenderer<COMP>
|
||||||
where
|
where
|
||||||
COMP: BaseComponent,
|
COMP: BaseComponent,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user