2021-01-20 17:04:27 +00:00
|
|
|
//! <div align="center">
|
|
|
|
//! <h1>🌗🚀 📦 Dioxus</h1>
|
|
|
|
//! <p>
|
|
|
|
//! <strong>A concurrent, functional, virtual DOM for Rust</strong>
|
|
|
|
//! </p>
|
|
|
|
//! </div>
|
|
|
|
//! Dioxus: a concurrent, functional, reactive virtual dom for any renderer in Rust.
|
2021-01-15 07:52:47 +00:00
|
|
|
//!
|
2021-01-20 17:04:27 +00:00
|
|
|
//! This crate aims to maintain a uniform hook-based, renderer-agnostic UI framework for cross-platform development.
|
|
|
|
//!
|
|
|
|
//! ## Components
|
|
|
|
//! The base unit of Dioxus is the `component`. Components can be easily created from just a function - no traits required:
|
|
|
|
//! ```
|
|
|
|
//! use dioxus_core::prelude::*;
|
|
|
|
//!
|
2021-01-29 16:57:52 +00:00
|
|
|
//! #[derive(Properties)]
|
|
|
|
//! struct Props { name: String }
|
|
|
|
//!
|
|
|
|
//! fn Example(ctx: &mut Context<Props>) -> VNode {
|
|
|
|
//! html! { <div> "Hello {ctx.props.name}!" </div> }
|
2021-01-20 17:04:27 +00:00
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//! Components need to take a "Context" parameter which is generic over some properties. This defines how the component can be used
|
2021-01-29 16:57:52 +00:00
|
|
|
//! and what properties can be used to specify it in the VNode output. Component state in Dioxus is managed by hooks - if you're new
|
|
|
|
//! to hooks, check out the hook guide in the official guide.
|
|
|
|
//!
|
|
|
|
//! Components can also be crafted as static closures, enabling type inference without all the type signature noise:
|
|
|
|
//! ```
|
|
|
|
//! use dioxus_core::prelude::*;
|
|
|
|
//!
|
|
|
|
//! #[derive(Properties)]
|
|
|
|
//! struct Props { name: String }
|
|
|
|
//!
|
2021-02-12 04:03:01 +00:00
|
|
|
//! static Example: FC<Props> = |ctx, props| {
|
|
|
|
//! html! { <div> "Hello {props.name}!" </div> }
|
2021-01-29 16:57:52 +00:00
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! If the properties struct is too noisy for you, we also provide a macro that converts variadic functions into components automatically.
|
|
|
|
//! ```
|
|
|
|
//! use dioxus_core::prelude::*;
|
|
|
|
//!
|
2021-02-12 04:03:01 +00:00
|
|
|
//! #[fc]
|
2021-01-29 16:57:52 +00:00
|
|
|
//! static Example: FC = |ctx, name: String| {
|
|
|
|
//! html! { <div> "Hello {name}!" </div> }
|
|
|
|
//! }
|
|
|
|
//! ```
|
2021-01-20 17:04:27 +00:00
|
|
|
//!
|
|
|
|
//! ## Hooks
|
|
|
|
//! Dioxus uses hooks for state management. Hooks are a form of state persisted between calls of the function component. Instead of
|
|
|
|
//! using a single struct to store data, hooks use the "use_hook" building block which allows the persistence of data between
|
|
|
|
//! function component renders.
|
|
|
|
//!
|
|
|
|
//! This allows functions to reuse stateful logic between components, simplify large complex components, and adopt more clear context
|
|
|
|
//! subscription patterns to make components easier to read.
|
|
|
|
//!
|
|
|
|
//! ## Supported Renderers
|
|
|
|
//! Instead of being tightly coupled to a platform, browser, or toolkit, Dioxus implements a VirtualDOM object which
|
|
|
|
//! can be consumed to draw the UI. The Dioxus VDOM is reactive and easily consumable by 3rd-party renderers via
|
|
|
|
//! the `Patch` object. See [Implementing a Renderer](docs/8-custom-renderer.md) and the `StringRenderer` classes for information
|
|
|
|
//! on how to implement your own custom renderer. We provide 1st-class support for these renderers:
|
|
|
|
//! - dioxus-desktop (via WebView)
|
|
|
|
//! - dioxus-web (via WebSys)
|
|
|
|
//! - dioxus-ssr (via StringRenderer)
|
|
|
|
//! - dioxus-liveview (SSR + StringRenderer)
|
|
|
|
//!
|
2021-01-14 07:56:41 +00:00
|
|
|
|
2021-02-15 04:39:46 +00:00
|
|
|
// pub mod changelist; // An "edit phase" described by transitions and edit operations
|
2021-02-14 23:03:16 +00:00
|
|
|
pub mod component; // Logic for extending FC
|
|
|
|
pub mod context; // Logic for providing hook + context functionality to user components
|
|
|
|
pub mod debug_renderer; // Test harness for validating that lifecycles and diffs work appropriately
|
2021-02-15 04:39:46 +00:00
|
|
|
pub mod diff;
|
|
|
|
pub mod patch; // The diffing algorithm that builds the ChangeList
|
|
|
|
// pub mod dodriodiff; // The diffing algorithm that builds the ChangeList
|
2021-02-14 23:03:16 +00:00
|
|
|
pub mod error; // Error type we expose to the renderers
|
|
|
|
pub mod events; // Manages the synthetic event API
|
|
|
|
pub mod hooks; // Built-in hooks
|
|
|
|
pub mod nodebuilder; // Logic for building VNodes with a direct syntax
|
|
|
|
pub mod nodes; // Logic for the VNodes
|
|
|
|
pub mod scope; // Logic for single components
|
|
|
|
pub mod validation; // Logic for validating trees
|
|
|
|
pub mod virtual_dom; // Most fun logic starts here, manages the lifecycle and suspense
|
2021-02-03 07:26:04 +00:00
|
|
|
|
2021-02-07 03:19:56 +00:00
|
|
|
pub mod builder {
|
|
|
|
pub use super::nodebuilder::*;
|
|
|
|
}
|
|
|
|
|
2021-02-07 22:38:17 +00:00
|
|
|
// types used internally that are important
|
2021-02-12 21:11:33 +00:00
|
|
|
pub(crate) mod innerlude {
|
2021-02-07 22:38:17 +00:00
|
|
|
pub use crate::component::{Component, Properties};
|
2021-02-12 04:03:01 +00:00
|
|
|
use crate::context::hooks::Hook;
|
2021-02-08 00:14:04 +00:00
|
|
|
pub use crate::context::Context;
|
2021-02-12 08:07:35 +00:00
|
|
|
pub use crate::error::{Error, Result};
|
2021-02-07 22:38:17 +00:00
|
|
|
use crate::nodes;
|
2021-02-12 04:03:01 +00:00
|
|
|
pub use crate::scope::Scope;
|
2021-02-07 22:38:17 +00:00
|
|
|
pub use crate::virtual_dom::VirtualDom;
|
|
|
|
pub use nodes::*;
|
|
|
|
|
|
|
|
// pub use nodes::iterables::IterableNodes;
|
|
|
|
/// This type alias is an internal way of abstracting over the static functions that represent components.
|
2021-02-12 04:03:01 +00:00
|
|
|
|
|
|
|
pub type FC<P> = for<'a> fn(Context<'a>, &'a P) -> VNode<'a>;
|
|
|
|
// pub type FC<P> = for<'a> fn(Context<'a, P>) -> VNode<'a>;
|
2021-02-07 22:38:17 +00:00
|
|
|
|
|
|
|
// TODO @Jon, fix this
|
|
|
|
// hack the VNode type until VirtualNode is fixed in the macro crate
|
|
|
|
pub type VirtualNode<'a> = VNode<'a>;
|
|
|
|
|
|
|
|
// Re-export the FC macro
|
|
|
|
pub use crate as dioxus;
|
|
|
|
pub use crate::nodebuilder as builder;
|
|
|
|
pub use dioxus_core_macro::fc;
|
|
|
|
pub use dioxus_html_2::html;
|
|
|
|
}
|
|
|
|
|
2021-01-15 07:52:47 +00:00
|
|
|
/// Re-export common types for ease of development use.
|
|
|
|
/// Essential when working with the html! macro
|
2021-01-15 01:56:28 +00:00
|
|
|
pub mod prelude {
|
2021-02-07 22:38:17 +00:00
|
|
|
pub use crate::component::{Component, Properties};
|
2021-02-08 00:14:04 +00:00
|
|
|
pub use crate::context::Context;
|
2021-01-15 07:52:47 +00:00
|
|
|
use crate::nodes;
|
2021-02-07 22:38:17 +00:00
|
|
|
pub use crate::virtual_dom::VirtualDom;
|
2021-01-15 07:52:47 +00:00
|
|
|
pub use nodes::*;
|
2021-02-03 07:26:04 +00:00
|
|
|
|
2021-02-07 22:38:17 +00:00
|
|
|
// pub use nodes::iterables::IterableNodes;
|
2021-02-03 19:07:07 +00:00
|
|
|
/// This type alias is an internal way of abstracting over the static functions that represent components.
|
2021-02-12 21:11:33 +00:00
|
|
|
pub use crate::innerlude::FC;
|
2021-01-15 07:52:47 +00:00
|
|
|
|
2021-01-20 17:04:27 +00:00
|
|
|
// TODO @Jon, fix this
|
|
|
|
// hack the VNode type until VirtualNode is fixed in the macro crate
|
2021-02-03 07:26:04 +00:00
|
|
|
pub type VirtualNode<'a> = VNode<'a>;
|
2021-01-16 04:25:29 +00:00
|
|
|
|
2021-02-07 22:38:17 +00:00
|
|
|
// expose our bumpalo type
|
2021-02-07 03:19:56 +00:00
|
|
|
pub use bumpalo;
|
2021-02-03 19:07:07 +00:00
|
|
|
|
|
|
|
// Re-export the FC macro
|
2021-02-07 03:19:56 +00:00
|
|
|
pub use crate as dioxus;
|
|
|
|
pub use crate::nodebuilder as builder;
|
2021-02-07 22:38:17 +00:00
|
|
|
pub use dioxus_core_macro::fc;
|
|
|
|
pub use dioxus_html_2::html;
|
2021-02-12 05:29:46 +00:00
|
|
|
|
2021-02-15 04:39:46 +00:00
|
|
|
pub use crate::diff::DiffMachine;
|
|
|
|
|
2021-02-12 05:29:46 +00:00
|
|
|
pub use crate::hooks::*;
|
2021-01-15 01:56:28 +00:00
|
|
|
}
|