dioxus/packages/core/src/lib.rs

142 lines
4.7 KiB
Rust
Raw Normal View History

#![allow(non_snake_case)]
2021-07-29 22:04:09 +00:00
#![doc = include_str!("../README.md")]
2022-02-20 22:37:46 +00:00
#![deny(missing_docs)]
2021-01-14 07:56:41 +00:00
2022-05-05 20:50:33 +00:00
pub(crate) mod arbitrary_value;
pub(crate) mod diff;
pub(crate) mod dynamic_template_context;
2022-01-03 07:06:42 +00:00
pub(crate) mod events;
pub(crate) mod lazynodes;
pub(crate) mod mutations;
pub(crate) mod nodes;
2022-01-03 07:06:42 +00:00
pub(crate) mod properties;
2021-12-21 03:33:13 +00:00
pub(crate) mod scopes;
pub(crate) mod template;
2022-01-03 07:06:42 +00:00
pub(crate) mod util;
pub(crate) mod virtual_dom;
2021-02-03 07:26:04 +00:00
2021-02-12 21:11:33 +00:00
pub(crate) mod innerlude {
2022-05-05 20:50:33 +00:00
pub use crate::arbitrary_value::*;
pub use crate::dynamic_template_context::*;
2022-01-03 07:06:42 +00:00
pub use crate::events::*;
2021-11-01 06:41:23 +00:00
pub use crate::lazynodes::*;
2021-08-22 21:08:25 +00:00
pub use crate::mutations::*;
2021-05-15 16:03:08 +00:00
pub use crate::nodes::*;
2022-01-03 07:06:42 +00:00
pub use crate::properties::*;
2021-12-21 03:33:13 +00:00
pub use crate::scopes::*;
pub use crate::template::*;
2022-01-03 07:06:42 +00:00
pub use crate::util::*;
2021-05-15 16:03:08 +00:00
pub use crate::virtual_dom::*;
2021-11-01 06:41:23 +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>>;
/// 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
///
2022-01-03 06:12:39 +00:00
/// ```rust, ignore
/// fn example(cx: Scope<Props>) -> Element {
/// // ...
/// }
///
/// rsx!(
/// example()
/// )
/// ```
/// ## React-Style
2022-01-03 06:12:39 +00:00
/// ```rust, ignore
/// fn Example(cx: Scope<Props>) -> Element {
/// // ...
/// }
///
/// rsx!(
/// Example {}
/// )
/// ```
pub type Component<P = ()> = fn(Scope<P>) -> Element;
/// A list of attributes
pub type Attributes<'a> = Option<&'a [Attribute<'a>]>;
2021-07-11 23:31:07 +00:00
}
2021-02-12 05:29:46 +00:00
2021-08-31 16:28:44 +00:00
pub use crate::innerlude::{
AnyEvent, ArbitraryAttributeValue, Attribute, AttributeDiscription, AttributeValue,
CodeLocation, Component, DioxusElement, DomEdit, DynamicNodeMapping, Element, ElementId,
ElementIdIterator, EventHandler, EventPriority, GlobalNodeId, IntoVNode, LazyNodes, Listener,
Mutations, NodeFactory, OwnedAttributeValue, Properties, RendererTemplateId, SchedulerMsg,
Scope, ScopeId, ScopeState, StaticCodeLocation, StaticDynamicNodeMapping, StaticTemplateNode,
StaticTemplateNodes, TaskId, Template, TemplateAttribute, TemplateAttributeValue,
TemplateContext, TemplateElement, TemplateId, TemplateNode, TemplateNodeId, TemplateNodeType,
TemplateValue, TextTemplate, TextTemplateSegment, UiEvent, UserEvent, VComponent, VElement,
VFragment, VNode, VPlaceholder, VText, VirtualDom, JS_MAX_INT,
};
#[cfg(any(feature = "hot-reload", debug_assertions))]
pub use crate::innerlude::{
OwnedCodeLocation, OwnedDynamicNodeMapping, OwnedTemplateNode, OwnedTemplateNodes,
SetTemplateMsg,
2021-08-31 16:28:44 +00:00
};
2022-02-20 22:37:46 +00:00
/// The purpose of this module is to alleviate imports of many common types
///
/// This includes types like [`Scope`], [`Element`], and [`Component`].
2021-08-31 16:28:44 +00:00
pub mod prelude {
pub use crate::get_line_num;
#[cfg(any(feature = "hot-reload", debug_assertions))]
pub use crate::innerlude::OwnedTemplate;
2021-12-10 02:19:31 +00:00
pub use crate::innerlude::{
fc_to_builder, AttributeDiscription, AttributeValue, Attributes, CodeLocation, Component,
DioxusElement, Element, EventHandler, Fragment, LazyNodes, LazyStaticVec, NodeFactory,
Properties, Scope, ScopeId, ScopeState, StaticAttributeValue, StaticCodeLocation,
StaticDynamicNodeMapping, StaticTemplate, StaticTemplateNodes, Template, TemplateAttribute,
TemplateAttributeValue, TemplateContext, TemplateElement, TemplateId, TemplateNode,
TemplateNodeId, TemplateNodeType, TextTemplate, TextTemplateSegment, VNode, VirtualDom,
2021-12-10 02:19:31 +00:00
};
2021-08-31 16:28:44 +00:00
}
2021-07-11 23:31:07 +00:00
pub mod exports {
2021-08-25 19:54:33 +00:00
//! Important dependencies that are used by the rest of the library
2021-12-15 03:48:20 +00:00
//! Feel free to just add the dependencies in your own Crates.toml
pub use bumpalo;
2021-10-04 05:28:04 +00:00
pub use futures_channel;
pub use once_cell;
2021-01-15 01:56:28 +00:00
}
2021-12-21 03:33:13 +00:00
/// Functions that wrap unsafe functionality to prevent us from misusing it at the callsite
pub(crate) mod unsafe_utils {
use crate::VNode;
2022-01-03 07:06:42 +00:00
pub(crate) unsafe fn extend_vnode<'a, 'b>(node: &'a VNode<'a>) -> &'b VNode<'b> {
2021-12-21 03:33:13 +00:00
std::mem::transmute(node)
}
}
2022-03-02 22:56:12 +00:00
#[macro_export]
/// A helper macro for using hooks in async environements.
///
/// # Usage
///
///
/// ```ignore
2022-03-02 22:56:12 +00:00
/// 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();
)*}
}