1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#![cfg_attr(feature = "nightly-features", feature(debug_refcell))]
#[macro_export]
/// A helper macro for using hooks and properties in async environements.
///
/// # Usage
///
///
/// ```
/// # use dioxus::prelude::*;
/// #
/// # #[derive(Props, PartialEq)]
/// # struct Props {
/// # prop: String,
/// # }
/// # fn Component(cx: Scope<Props>) -> Element {
///
/// let (data) = use_ref(cx, || {});
///
/// let handle_thing = move |_| {
/// to_owned![data, cx.props.prop];
/// cx.spawn(async move {
/// // do stuff
/// });
/// };
/// # handle_thing(());
/// # None }
/// ```
macro_rules! to_owned {
// Rule matching simple symbols without a path
($es:ident $(, $($rest:tt)*)?) => {
#[allow(unused_mut)]
let mut $es = $es.to_owned();
$( to_owned![$($rest)*] )?
};
// We need to find the last element in a path, for this we need to unstack the path part by
// part using, separating what we have with a '@'
($($deref:ident).* $(, $($rest:tt)*)?) => {
to_owned![@ $($deref).* $(, $($rest)*)?]
};
// Take the head of the path and add it to the list of $deref
($($deref:ident)* @ $head:ident $( . $tail:ident)+ $(, $($rest:tt)*)?) => {
to_owned![$($deref)* $head @ $($tail).+ $(, $($rest)*)?]
};
// We have exhausted the path, use the last as a name
($($deref:ident)* @ $last:ident $(, $($rest:tt)*)? ) => {
#[allow(unused_mut)]
let mut $last = $($deref .)* $last .to_owned();
$(to_owned![$($rest)*])?
};
}
mod computed;
pub use computed::*;
mod use_on_unmount;
pub use use_on_unmount::*;
mod usecontext;
pub use usecontext::*;
mod usestate;
pub use usestate::{use_state, UseState};
mod useref;
pub use useref::*;
mod use_shared_state;
pub use use_shared_state::*;
mod usecoroutine;
pub use usecoroutine::*;
mod usefuture;
pub use usefuture::*;
mod useeffect;
pub use useeffect::*;
mod usecallback;
pub use usecallback::*;
mod usememo;
pub use usememo::*;
mod userootcontext;
pub use userootcontext::*;