2021-01-20 12:04:27 -05: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 02:52:47 -05:00
//!
2021-05-28 12:56:21 -04:00
//! This crate aims to maintain a hook-based, renderer-agnostic framework for cross-platform UI development.
2021-01-20 12:04:27 -05:00
//!
//! ## 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 11:57:52 -05:00
//! #[derive(Properties)]
//! struct Props { name: String }
//!
2021-06-01 18:33:15 -04:00
//! fn Example(ctx: Context, props: &Props) -> VNode {
//! html! { <div> "Hello {ctx.name}!" </div> }
2021-01-20 12:04:27 -05: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 11:57:52 -05: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-06-01 18:33:15 -04:00
//! static Example: FC<Props> = |ctx| {
//! html! { <div> "Hello {ctx.name}!" </div> }
2021-01-29 11:57:52 -05:00
//! }
//! ```
//!
//! If the properties struct is too noisy for you, we also provide a macro that converts variadic functions into components automatically.
2021-05-28 12:56:21 -04:00
//! Many people don't like the magic of proc macros, so this is entirely optional. Under-the-hood, we simply transplant the
//! function arguments into a struct, so there's very little actual magic happening.
//!
2021-01-29 11:57:52 -05:00
//! ```
//! use dioxus_core::prelude::*;
//!
2021-05-28 12:56:21 -04:00
//! #[derive_props]
//! static Example: FC = |ctx, name: &String| {
2021-01-29 11:57:52 -05:00
//! html! { <div> "Hello {name}!" </div> }
//! }
//! ```
2021-01-20 12:04:27 -05: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
2021-05-28 12:56:21 -04:00
//! function component renders. Each hook stores some data in a "memory cell" and needs to be called in a consistent order.
//! This means hooks "anything with `use_x`" may not be called conditionally.
2021-01-20 12:04:27 -05:00
//!
//! 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 02:56:41 -05:00
2021-05-16 02:55:16 -04:00
pub mod arena ;
2021-02-14 18:03:16 -05:00
pub mod component ; // Logic for extending FC
2021-05-28 12:56:21 -04:00
2021-03-03 02:27:26 -05:00
pub mod debug_renderer ;
pub mod diff ;
2021-05-15 12:03:08 -04:00
pub mod patch ; // An "edit phase" described by transitions and edit operations // Test harness for validating that lifecycles and diffs work appropriately
// the diffing algorithm that builds the ChangeList
2021-02-14 18:03:16 -05: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 virtual_dom ; // Most fun logic starts here, manages the lifecycle and suspense
2021-02-03 02:26:04 -05:00
2021-02-06 22:19:56 -05:00
pub mod builder {
pub use super ::nodebuilder ::* ;
}
2021-06-07 14:14:49 -04:00
2021-06-05 23:47:54 -04:00
pub mod support ;
2021-02-06 22:19:56 -05:00
2021-02-07 17:38:17 -05:00
// types used internally that are important
2021-02-12 16:11:33 -05:00
pub ( crate ) mod innerlude {
2021-05-15 12:03:08 -04:00
pub use crate ::component ::* ;
2021-05-28 12:56:21 -04:00
2021-05-15 12:03:08 -04:00
pub use crate ::debug_renderer ::* ;
pub use crate ::diff ::* ;
pub use crate ::error ::* ;
pub use crate ::events ::* ;
pub use crate ::hooks ::* ;
pub use crate ::nodebuilder ::* ;
pub use crate ::nodes ::* ;
pub use crate ::patch ::* ;
pub use crate ::virtual_dom ::* ;
2021-02-11 23:03:01 -05:00
2021-06-01 18:33:15 -04:00
pub type FC < P > = fn ( Context < P > ) -> VNode ;
2021-02-20 21:59:16 -05:00
2021-02-07 17:38:17 -05:00
// Re-export the FC macro
pub use crate as dioxus ;
pub use crate ::nodebuilder as builder ;
2021-03-07 21:28:20 -05:00
pub use dioxus_core_macro ::{ html , rsx } ;
2021-02-07 17:38:17 -05:00
}
2021-01-15 02:52:47 -05:00
/// Re-export common types for ease of development use.
/// Essential when working with the html! macro
2021-01-14 20:56:28 -05:00
pub mod prelude {
2021-03-09 14:45:52 -05:00
pub use crate ::component ::{ fc_to_builder , Properties } ;
2021-01-15 02:52:47 -05:00
use crate ::nodes ;
2021-05-16 02:06:02 -04:00
pub use crate ::virtual_dom ::Context ;
2021-06-03 12:02:46 -04:00
pub use crate ::virtual_dom ::Scoped ;
2021-01-15 02:52:47 -05:00
pub use nodes ::* ;
2021-02-03 02:26:04 -05:00
2021-03-22 23:52:54 -04:00
pub use crate ::nodebuilder ::LazyNodes ;
2021-05-16 02:06:02 -04:00
pub use crate ::virtual_dom ::NodeCtx ;
2021-02-07 17:38:17 -05:00
// pub use nodes::iterables::IterableNodes;
2021-02-03 14:07:07 -05:00
/// This type alias is an internal way of abstracting over the static functions that represent components.
2021-03-09 00:58:20 -05:00
pub use crate ::innerlude ::FC ;
2021-01-15 02:52:47 -05:00
2021-01-20 12:04:27 -05:00
// TODO @Jon, fix this
// hack the VNode type until VirtualNode is fixed in the macro crate
2021-01-15 23:25:29 -05:00
2021-02-07 17:38:17 -05:00
// expose our bumpalo type
2021-02-06 22:19:56 -05:00
pub use bumpalo ;
2021-03-03 02:27:26 -05:00
pub use bumpalo ::Bump ;
2021-02-03 14:07:07 -05:00
// Re-export the FC macro
2021-02-06 22:19:56 -05:00
pub use crate as dioxus ;
pub use crate ::nodebuilder as builder ;
2021-02-26 20:42:55 -05:00
// pub use dioxus_core_macro::fc;
2021-03-09 00:58:20 -05:00
pub use dioxus_core_macro ::{ format_args_f , html , rsx , Props } ;
2021-02-12 00:29:46 -05:00
2021-03-03 02:27:26 -05:00
pub use crate ::component ::ScopeIdx ;
pub use crate ::diff ::DiffMachine ;
2021-02-14 23:39:46 -05:00
2021-03-12 16:58:30 -05:00
pub use crate ::debug_renderer ::DebugRenderer ;
2021-05-26 01:40:30 -04:00
pub use crate ::dioxus_main ;
2021-02-12 00:29:46 -05:00
pub use crate ::hooks ::* ;
2021-01-14 20:56:28 -05:00
}
2021-05-26 01:40:30 -04:00
#[ macro_export ]
macro_rules ! dioxus_main {
( $i :ident ) = > {
fn main ( ) {
todo! ( " this macro is a placeholder for launching a dioxus app on different platforms. \n You probably don't want to use this, but it's okay for small apps. " )
}
} ;
}