dioxus/packages/core/src/lib.rs

135 lines
3.1 KiB
Rust
Raw Normal View History

mod any_props;
mod arena;
mod bump_frame;
mod component;
mod create;
mod diff;
2022-11-02 01:42:29 +00:00
mod events;
mod factory;
mod garbage;
mod lazynodes;
mod mutations;
mod nodes;
2022-11-03 00:29:18 +00:00
mod properties;
2022-11-06 08:48:34 +00:00
mod scheduler;
mod scope_arena;
mod scopes;
2022-11-02 01:42:29 +00:00
mod virtualdom;
2022-11-02 01:42:29 +00:00
pub(crate) mod innerlude {
2022-11-03 08:38:18 +00:00
pub use crate::arena::*;
2022-11-02 01:42:29 +00:00
pub use crate::events::*;
2022-11-03 00:29:18 +00:00
pub use crate::lazynodes::*;
2022-11-02 01:42:29 +00:00
pub use crate::mutations::*;
pub use crate::nodes::*;
2022-11-03 00:29:18 +00:00
pub use crate::properties::*;
2022-11-06 08:48:34 +00:00
pub use crate::scheduler::*;
2022-11-02 01:42:29 +00:00
pub use crate::scopes::*;
pub use crate::virtualdom::*;
2021-02-12 05:29:46 +00:00
2022-11-03 08:38:18 +00:00
/// An [`Element`] is a possibly-none [`VNode`] created by calling `render` on [`Scope`] or [`ScopeState`].
///
/// Any [`None`] [`Element`] will automatically be coerced into a placeholder [`VNode`] with the [`VNode::Placeholder`] variant.
pub type Element<'a> = Option<VNode<'a>>;
2021-08-31 16:28:44 +00:00
2022-11-02 01:42:29 +00:00
/// A [`Component`] is a function that takes a [`Scope`] and returns an [`Element`].
///
/// Components can be used in other components with two syntax options:
/// - lowercase as a function call with named arguments (rust style)
/// - uppercase as an element (react style)
///
/// ## Rust-Style
///
/// ```rust, ignore
/// fn example(cx: Scope<Props>) -> Element {
/// // ...
/// }
///
/// rsx!(
/// example()
/// )
/// ```
/// ## React-Style
/// ```rust, ignore
/// fn Example(cx: Scope<Props>) -> Element {
/// // ...
/// }
///
/// rsx!(
/// Example {}
/// )
/// ```
pub type Component<P = ()> = fn(Scope<P>) -> Element;
2021-08-31 16:28:44 +00:00
2022-11-02 01:42:29 +00:00
/// A list of attributes
pub type Attributes<'a> = Option<&'a [Attribute<'a>]>;
}
2021-12-21 03:33:13 +00:00
2022-11-02 01:42:29 +00:00
pub use crate::innerlude::{
2022-11-03 08:38:18 +00:00
// AnyAttributeValue, AnyEvent,
2022-11-03 00:29:18 +00:00
fc_to_builder,
2022-11-02 01:42:29 +00:00
Attribute,
AttributeValue,
2022-11-03 08:38:18 +00:00
Attributes,
Component,
2022-11-02 08:00:37 +00:00
DynamicNode,
2022-11-02 01:42:29 +00:00
Element,
2022-11-03 08:38:18 +00:00
ElementId,
ElementPath,
2022-11-02 01:42:29 +00:00
EventPriority,
LazyNodes,
NodeFactory,
2022-11-03 00:29:18 +00:00
Properties,
2022-11-02 01:42:29 +00:00
Scope,
ScopeId,
ScopeState,
TaskId,
Template,
TemplateAttribute,
TemplateNode,
UiEvent,
VNode,
VirtualDom,
};
2022-03-02 22:56:12 +00:00
2022-11-02 01:42:29 +00:00
/// The purpose of this module is to alleviate imports of many common types
///
/// This includes types like [`Scope`], [`Element`], and [`Component`].
pub mod prelude {
pub use crate::innerlude::{
2022-11-03 08:24:20 +00:00
fc_to_builder, Attribute, DynamicNode, Element, EventPriority, LazyNodes, NodeFactory,
Properties, Scope, ScopeId, ScopeState, TaskId, Template, TemplateAttribute, TemplateNode,
UiEvent, VNode, VirtualDom,
2022-11-02 01:42:29 +00:00
};
}
2022-11-02 01:42:29 +00:00
pub mod exports {
//! Important dependencies that are used by the rest of the library
//! Feel free to just add the dependencies in your own Crates.toml
pub use bumpalo;
pub use futures_channel;
}
2022-11-02 01:42:29 +00:00
#[macro_export]
/// A helper macro for using hooks in async environements.
///
/// # Usage
///
///
/// ```ignore
/// let (data) = use_ref(&cx, || {});
///
/// let handle_thing = move |_| {
/// to_owned![data]
/// cx.spawn(async move {
/// // do stuff
/// });
/// }
/// ```
macro_rules! to_owned {
($($es:ident),+) => {$(
#[allow(unused_mut)]
let mut $es = $es.to_owned();
)*}
}