dioxus/packages/core/src/lib.rs

148 lines
3.3 KiB
Rust
Raw Normal View History

mod any_props;
mod arena;
mod bump_frame;
mod create;
mod diff;
2022-11-23 02:38:27 +00:00
mod dirty_scope;
mod error_boundary;
2022-11-02 01:42:29 +00:00
mod events;
mod factory;
2022-11-20 01:07:29 +00:00
mod fragment;
2022-11-02 01:42:29 +00:00
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-09 03:39:37 +00:00
mod virtual_dom;
2022-11-23 03:59:56 +00:00
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-23 02:38:27 +00:00
pub use crate::dirty_scope::*;
2022-11-02 01:42:29 +00:00
pub use crate::events::*;
2022-11-20 01:07:29 +00:00
pub use crate::fragment::*;
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::*;
2022-11-09 03:39:37 +00:00
pub use crate::virtual_dom::*;
2021-02-12 05:29:46 +00:00
2022-11-23 02:38:27 +00:00
/// An [`Element`] is a possibly-errored [`VNode`] created by calling `render` on [`Scope`] or [`ScopeState`].
2022-11-03 08:38:18 +00:00
///
2022-11-23 02:38:27 +00:00
/// An Errored [`Element`] will propagate the error to the nearest error boundary.
pub type Element<'a> = anyhow::Result<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,
2022-11-18 04:00:39 +00:00
ElementRef,
2022-11-02 01:42:29 +00:00
EventPriority,
2022-11-12 02:29:27 +00:00
Fragment,
2022-11-02 01:42:29 +00:00
LazyNodes,
2022-11-12 02:29:27 +00:00
Mutation,
Mutations,
2022-11-02 01:42:29 +00:00
NodeFactory,
2022-11-03 00:29:18 +00:00
Properties,
2022-11-02 01:42:29 +00:00
Scope,
ScopeId,
ScopeState,
2022-11-09 03:39:37 +00:00
Scoped,
SuspenseBoundary,
SuspenseContext,
2022-11-02 01:42:29 +00:00
TaskId,
Template,
TemplateAttribute,
TemplateNode,
2022-11-16 00:37:23 +00:00
UiEvent,
2022-11-22 01:00:34 +00:00
VComponent,
VFragment,
2022-11-02 01:42:29 +00:00
VNode,
2022-11-22 01:00:34 +00:00
VText,
2022-11-02 01:42:29 +00:00
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-16 00:05:22 +00:00
fc_to_builder, Element, EventHandler, EventPriority, Fragment, LazyNodes, NodeFactory,
Properties, Scope, ScopeId, ScopeState, Scoped, TaskId, Template, TemplateAttribute,
2022-11-16 00:37:23 +00:00
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();
)*}
}