Improve inline docs (#2460)

Improve inline docs

* improve incorrect event handler return error message

* Improve event handler docs

* document the eval functions

* document spawn and common spawn errors

* fix event handler docs

* add notes about how you use attributes and elements in rsx

* add doc aliases for attributes and events we rename

* add some more aliases for common search terms

* don't doc ignore any public examples in core

* don't ignore public doc examples in ssr

* don't ignore examples in the dioxus package readme

* add a warning when you launch without a renderer enabled

* fix some outdated element docs

* add a bunch of examples to resource

* add notes about desktop events

* add more docs for use_resource

* add on_unimplemented hint to Dependency

* fix some unresolved links

* add examples to each of the router traits

* add not implemented errors for router traits

* add an example to the routable trait

* expand rsx macro docs

* improve memo docs

* update the dioxus readme

* mention dioxus crate features in the docs

* fix a bunch of doc tests

* fix html doc tests

* fix router doc tests

* fix dioxus signals doc tests

* fix dioxus ssr doc tests

* fix use_future example in the hooks cheat sheet

* add a javascript alias for eval

* fix hook explanation values

* remove unused embed-doc-image dependency
This commit is contained in:
Evan Almloff authored and GitHub committed 2024-06-06 18:15:17 -07:00
1 parent 054351139f
commit 0127501dbf
71 files changed
+4132 -1162

No files matched your search

+44 -36
View File
@@ -12,15 +12,15 @@ use std::{
///
/// # Example
///
/// ```rust, ignore
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// rsx! {
/// button {
/// onclick: move |evt: Event<MouseData>| {
/// evt.cancel_bubble();
///
/// evt.stop_propagation();
/// }
/// }
/// }
/// };
/// ```
pub struct Event<T: 'static + ?Sized> {
/// The data associated with this event
@@ -42,15 +42,16 @@ impl<T> Event<T> {
///
/// # Example
///
/// ```rust, ignore
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// rsx! {
/// button {
/// onclick: move |evt: Event<FormData>| {
/// let data = evt.map(|data| data.value());
/// assert_eq!(data.inner(), "hello world");
/// onclick: move |evt: MouseEvent| {
/// let data = evt.map(|data| data.client_coordinates());
/// println!("{:?}", data.data());
/// }
/// }
/// }
/// };
/// ```
pub fn map<U: 'static, F: FnOnce(&T) -> U>(&self, f: F) -> Event<U> {
Event {
@@ -63,14 +64,16 @@ impl<T> Event<T> {
///
/// # Example
///
/// ```rust, ignore
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// rsx! {
/// button {
/// onclick: move |evt: Event<MouseData>| {
/// # #[allow(deprecated)]
/// evt.cancel_bubble();
/// }
/// }
/// }
/// };
/// ```
#[deprecated = "use stop_propagation instead"]
pub fn cancel_bubble(&self) {
@@ -81,14 +84,15 @@ impl<T> Event<T> {
///
/// # Example
///
/// ```rust, ignore
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// rsx! {
/// button {
/// onclick: move |evt: Event<MouseData>| {
/// evt.stop_propagation();
/// }
/// }
/// }
/// };
/// ```
pub fn stop_propagation(&self) {
self.propagates.set(false);
@@ -96,17 +100,18 @@ impl<T> Event<T> {
/// Get a reference to the inner data from this event
///
/// ```rust, ignore
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// rsx! {
/// button {
/// onclick: move |evt: Event<MouseData>| {
/// let data = evt.inner.clone();
/// cx.spawn(async move {
/// let data = evt.data();
/// async move {
/// println!("{:?}", data);
/// });
/// }
/// }
/// }
/// }
/// };
/// ```
pub fn data(&self) -> Rc<T> {
self.data.clone()
@@ -145,12 +150,13 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
///
/// # Example
///
/// ```rust, ignore
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// rsx!{
/// MyComponent { onclick: move |evt| tracing::debug!("clicked") }
/// }
/// };
///
/// #[derive(Props)]
/// #[derive(Props, Clone, PartialEq)]
/// struct MyProps {
/// onclick: EventHandler<MouseEvent>,
/// }
@@ -162,26 +168,28 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
/// }
/// }
/// }
///
/// ```
pub struct EventHandler<T = ()> {
pub(crate) origin: ScopeId,
// During diffing components with EventHandler, we move the EventHandler over in place instead of rerunning the child component.
// ```rust
// #[component]
// fn Child(onclick: EventHandler<MouseEvent>) -> Element {
// rsx!{
// button {
// // Diffing Child will not rerun this component, it will just update the EventHandler in place so that if this callback is called, it will run the latest version of the callback
// onclick: move |evt| cx.onclick.call(evt),
// }
// }
/// During diffing components with EventHandler, we move the EventHandler over in place instead of rerunning the child component.
///
/// ```rust
/// # use dioxus::prelude::*;
/// #[component]
/// fn Child(onclick: EventHandler<MouseEvent>) -> Element {
/// rsx!{
/// button {
/// // Diffing Child will not rerun this component, it will just update the EventHandler in place so that if this callback is called, it will run the latest version of the callback
/// onclick: move |evt| onclick(evt),
/// }
/// }
/// }
/// ```
// This is both more efficient and allows us to avoid out of date EventHandlers.
//
// We double box here because we want the data to be copy (GenerationalBox) and still update in place (ExternalListenerCallback)
// This isn't an ideal solution for performance, but it is non-breaking and fixes the issues described in https://github.com/DioxusLabs/dioxus/pull/2298
///
/// This is both more efficient and allows us to avoid out of date EventHandlers.
///
/// We double box here because we want the data to be copy (GenerationalBox) and still update in place (ExternalListenerCallback)
/// This isn't an ideal solution for performance, but it is non-breaking and fixes the issues described in <https://github.com/DioxusLabs/dioxus/pull/2298>
pub(super) callback: GenerationalBox<Option<ExternalListenerCallback<T>>>,
}