diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..2f418701b --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "rust-analyzer.inlayHints.enable": true +} \ No newline at end of file diff --git a/.vscode/spellright.dict b/.vscode/spellright.dict new file mode 100644 index 000000000..e8ea08292 --- /dev/null +++ b/.vscode/spellright.dict @@ -0,0 +1 @@ +bearly diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..4b7145537 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Initial Release +- [ ] (Macro) Tweak event syntax to not be dependent on wasm32 target (just return regular closures) +- [ ] (Macro) Tweak component syntax to accept a new custom element +- [ ] (Core) Introduce the VDOM and patch API for 3rd party renderers +- [ ] (Web) Web-sys renderer and web tests +- [ ] (Examples) Tide example with templating diff --git a/Cargo.toml b/Cargo.toml index cbec6c247..1ab735542 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,15 @@ [workspace] members = [ - # Built-n + # Built-in "packages/core", "packages/macro", "packages/hooks", "packages/recoil", "packages/redux", + "packages/web", + # + # + # # Pulled from percy "packages/html-macro", "packages/html-macro-test", diff --git a/README.md b/README.md index ce02496cf..4156ee2ac 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# Dioxus: A concurrent, functional, arena-allocated VDOM implementation for creating UIs in Rust +# Dioxus: A concurrent, functional, virtual DOM for Rust Dioxus is a new approach for creating performant cross platform user experiences in Rust. In Dioxus, the UI is represented by a tree of Virtual Nodes not bound to any renderer framework. Instead, external renderers can leverage Dioxus' virtual DOM and event system as a source of truth for rendering to a medium of their choice. Developers used to crafting react-based experiences should feel comfortable with Dioxus. ## Hello World -Dioxus should look and feel just like writing functional React components. In Dioxus, there are no class components with lifecycles. All state management is done via hooks. This encourages logic resusability and lessens the burden on Dioxus to maintain a non-breaking lifecycle API. +Dioxus should look and feel just like writing functional React components. In Dioxus, there are no class components with lifecycles. All state management is done via hooks. This encourages logic reusability and lessens the burden on Dioxus to maintain a non-breaking lifecycle API. ```rust #[derive(Properties, PartialEq)] @@ -11,32 +11,79 @@ struct MyProps { name: String } -fn Example(ctx: Context) -> VNode { - html! {
"Hello {ctx.props().name}!"
} +fn Example(ctx: &Context) -> VNode { + html! {
"Hello {:?ctx.props().name}!"
} } ``` +Here, the `Context` object is used to access hook state, create subscriptions, and interact with the built-in context API. Props, children, and component APIs are accessible via the `Context` object. If using the functional component macro, it's possible to inline props into the function definition itself. +```rust +#[functional_component] +fn Example(ctx: &Context<{ name: String }>) -> VNode { + html! {
"Hello {:?name}!"
} +} +// or +#[functional_component] +static Example: FC<{ name: String }> = |ctx| html! {
"Hello {:?name}!"
}; +``` +The final output of components must be a tree of VNodes. We provide an html macro for using JSX-style syntax to write these, though, you could use any macro, dsl, or templating engine. Work is being done on a terra template processor for existing templates. - - - - -To build user interfaces, you must provide a way of creating VNodes. We provide a macro `dioxus-rsx` which makes it easy to drop in html templates and event listeners to make interactive user experiences. - -Inspired by React's Concurrent Mode, components in Dioxus are asynchronous by default. When components need to load asynchronous data, their rendering will be halted until ready, leading to fewer DOM updates and greater performance. External crates can tap into this system using futures to craft useful transition-based hooks. - -Rules of Dioxus: -- Every component is asynchronous -- Components will queued when completed -- +## Features Dioxus supports: - Hooks - Concurrent rendering - Context subscriptions +- Isomorphism +## Concurrency + +Dioxus, using React as a reference, provides the ability to have asynchronous components. With Dioxus, this is a valid component: + +```rust +async fn user_data(ctx: &Context<()>) -> VNode { + let Profile { name, birthday, .. } = use_context::(ctx).fetch_data().await; + html! { +
+ {"Hello, {:?name}!"} + {if birthday === std::Instant::now() {html! {"Happy birthday!"}}} +
+ } +} +``` + +Asynchronous components are powerful but can also be easy to misuse as they pause rendering for the component and its children. Refer to the concurrent guide for information on how to best use async components. + +## Example +- Isomorphic: serve a server-rendered webapp using Tide + +## Documentation +| Chapter | Description | +| -------------- | ------------------------------------------ | +| 1-hello-world | Intro to Dioxus | +| 2-utilities | Tools to make writing apps easier | +| 3-hello-world | Html + functional_component macro | +| 4-hello-world | Renderer + event integration using web_sys | +| 5-hello-world | Virtual DOM, patching/diffing | +| 6-hello-world | Standard bundle of useful hooks | +| 7-hello-world | Html + functional_component macro | +| 8-hello-world | Renderer + event integration using web_sys | +| 9-hello-world | Renderer + event integration using web_sys | +| 10-hello-world | Renderer + event integration using web_sys | + +## Packages +| Package | Use | +| --------- | ------------------------------------------ | +| core | Virtual DOM, patching/diffing | +| hooks | Standard bundle of useful hooks | +| macro | Html + functional_component macro | +| web | Renderer + event integration using web_sys | +| live-view | Dedicated isomorphic framework | +| recoil | Data-flow-graph state management | +| redux | Reducer-style state management | +| bearly | Simple and idiomatic state management | diff --git a/packages/core/Cargo.toml b/packages/core/Cargo.toml index 7d4e7c976..5e88acc03 100644 --- a/packages/core/Cargo.toml +++ b/packages/core/Cargo.toml @@ -9,3 +9,8 @@ edition = "2018" [dependencies] generational-arena = "0.2.8" typed-arena = "2.0.1" +virtual-dom-rs = { path = "../virtual-dom-rs" } +virtual-node = { path = "../virtual-node" } +html-macro = { path = "../html-macro" } +# web-sys = "0.3.46" +# js-sys = "0.3.46" diff --git a/packages/core/examples/simple.rs b/packages/core/examples/simple.rs new file mode 100644 index 000000000..07a5b14e4 --- /dev/null +++ b/packages/core/examples/simple.rs @@ -0,0 +1,75 @@ +use std::future::Future; + +use dioxus_core::{component::AnyContext, prelude::*}; +use virtual_dom_rs::Closure; + +pub fn main() { + let dom = VirtualDom::new(root); + let mut renderer = TextRenderer::new(dom); + let output = renderer.render(); +} + +fn root(ctx: &mut AnyContext) -> VirtualNode { + // the regular html syntax + + // html! { + // + // + // + //