dioxus/packages/core/src/lib.rs

150 lines
3.7 KiB
Rust
Raw Normal View History

mod any_props;
mod arena;
mod bump_frame;
mod component;
mod create;
mod diff;
mod element;
2022-11-02 01:42:29 +00:00
mod events;
mod factory;
mod future_container;
mod garbage;
mod lazynodes;
mod mutations;
mod nodes;
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 {
pub use crate::element::Element;
pub use crate::events::*;
pub use crate::future_container::*;
pub use crate::mutations::*;
pub use crate::nodes::*;
// pub use crate::properties::*;
pub use crate::lazynodes::*;
pub use crate::scopes::*;
pub use crate::virtualdom::*;
2021-02-12 05:29:46 +00:00
2022-11-02 01:42:29 +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<VNodea<'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::{
// AnyAttributeValue, AnyEvent, Attribute, AttributeValue, Component, Element, ElementId,
Attribute,
AttributeValue,
2022-11-02 08:00:37 +00:00
DynamicNode,
DynamicNodeKind,
2022-11-02 01:42:29 +00:00
Element,
EventPriority,
LazyNodes,
Listener,
NodeFactory,
Scope,
ScopeId,
ScopeState,
TaskId,
Template,
TemplateAttribute,
TemplateNode,
UiEvent,
VNode,
VirtualDom,
};
// EventHandler, EventPriority, IntoVNode, LazyNodes, Listener, NodeFactory, Properties, Renderer,
// SchedulerMsg, Scope, ScopeId, ScopeState, TaskId, Template, TemplateAttribute, TemplateNode,
// UiEvent, UserEvent, VComponent, VElement, VNode, VTemplate, VText, 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-02 08:00:37 +00:00
Attribute, DynamicNode, DynamicNodeKind, Element, EventPriority, LazyNodes, Listener,
NodeFactory, 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();
)*}
}
2022-11-02 01:42:29 +00:00
/// get the code location of the code that called this function
#[macro_export]
macro_rules! get_line_num {
() => {
concat!(
file!(),
":",
line!(),
":",
column!(),
":",
env!("CARGO_MANIFEST_DIR")
)
};
}