Renderers are now packages, not features. (#387)

* feat: use synchronous router design

* feat: function to get router out of dom

* chore: restructure workspace to use renderers as packages, not features
This commit is contained in:
Jon Kelley authored and GitHub committed 2022-07-09 15:15:20 -04:00
1 parent c97ca7dff6
commit d9546d9504
181 files changed
+487 -1463

No files matched your search

+11 -2
View File
@@ -6,7 +6,16 @@ description = "Dioxus guide, including testable examples"
license = "MIT/Apache-2.0"
[dev-dependencies]
dioxus = { path = "../..", features = ["desktop", "web", "ssr", "router", "fermi", "tui"] }
dioxus = { path = "../../packages/dioxus" }
dioxus-desktop = { path = "../../packages/desktop" }
dioxus-web = { path = "../../packages/web" }
dioxus-ssr = { path = "../../packages/ssr" }
dioxus-router = { path = "../../packages/router" }
dioxus-tui = { path = "../../packages/tui" }
fermi = { path = "../../packages/fermi" }
# dioxus = { path = "../../packages/dioxus", features = ["desktop", "web", "ssr", "router", "fermi", "tui"] }
serde = { version = "1.0.138", features=["derive"] }
reqwest = { version = "0.11.11", features = ["json"] }
tokio = { version = "1.19.2" , features=[]}
tokio = { version = "1.19.2" , features=[]}
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: App
+1 -1
View File
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: App
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: App
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
pub fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -4,7 +4,7 @@ use dioxus::events::MouseEvent;
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: component
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::tui::launch(App);
dioxus_tui::launch(App);
}
fn App(cx: Scope) -> Element {
@@ -3,16 +3,16 @@
use dioxus::events::{KeyCode, KeyboardEvent};
use dioxus::prelude::*;
use dioxus::tui::TuiContext;
use dioxus_tui::TuiContext;
fn main() {
dioxus::tui::launch_cfg(
dioxus_tui::launch_cfg(
App,
dioxus::tui::Config::new()
dioxus_tui::Config::new()
.without_ctrl_c_quit()
// Some older terminals only support 16 colors or ANSI colors
// If your terminal is one of these, change this to BaseColors or ANSI
.with_rendering_mode(dioxus::tui::RenderingMode::Rgb),
.with_rendering_mode(dioxus_tui::RenderingMode::Rgb),
);
}
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::web::launch(App);
dioxus_web::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -4,7 +4,7 @@ use dioxus::prelude::*;
use std::collections::HashMap;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: component
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: component
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: component
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: component
+1 -1
View File
@@ -2,7 +2,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: component
+1 -1
View File
@@ -5,7 +5,7 @@ use dioxus::events::FormEvent;
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(MemeEditor);
dioxus_desktop::launch(MemeEditor);
}
// ANCHOR: meme_editor
+1 -1
View File
@@ -5,7 +5,7 @@ use dioxus::events::FormEvent;
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
// ANCHOR: DarkMode_struct
+1 -1
View File
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
#[derive(PartialEq, Clone)]
+1 -1
View File
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
pub fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -3,7 +3,7 @@
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
#[derive(serde::Deserialize, Debug)]
@@ -33,7 +33,7 @@ let name = "jane";
let pending = false;
let count = 10;
dioxus::ssr::render_lazy(html! {
dioxus_ssr::render_lazy(html! {
<div>
<p> "Hello, {name}!" </p>
<p> "Status: {pending}!" </p>
@@ -51,7 +51,7 @@ When helpful, the Dioxus VSCode extension provides a way of converting a selecti
It's also a bit easier on the eyes than HTML.
```rust
dioxus::ssr::render_lazy(rsx! {
dioxus_ssr::render_lazy(rsx! {
div {
p {"Hello, {name}!"}
p {"Status: {pending}!"}
+1 -1
View File
@@ -159,7 +159,7 @@ force_render(ScopeId(0));
In our guides, we frequently use the phrase "re-render" to describe updates to our app. You'll often hear this paired with "preventing unnecessary re-renders." But what exactly does this mean?
When we call `dioxus::desktop::launch`, Dioxus will create a new `Scope` object and call the component we gave it. Our `rsx!` calls will create new nodes which we return back to the VirtualDom. Dioxus will then look through these nodes for child components, call their functions, and so on until every component has been "rendered." We consider these nodes "rendered" because they were created because of our explicit actions.
When we call `dioxus_desktop::launch`, Dioxus will create a new `Scope` object and call the component we gave it. Our `rsx!` calls will create new nodes which we return back to the VirtualDom. Dioxus will then look through these nodes for child components, call their functions, and so on until every component has been "rendered." We consider these nodes "rendered" because they were created because of our explicit actions.
The tree of UI that dioxus creates will roughly look like the tree of components presented earlier:
@@ -12,7 +12,7 @@ Instead of passing a closure, you can also pass a string to event handlers – t
use dioxus::prelude::*;
fn main() {
dioxus::desktop::launch(App);
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
+1 -1
View File
@@ -16,7 +16,7 @@ For the simplest of apps, all of your state can enter the app from the root prop
```rust
let all_content = get_all_content().await;
let output = dioxus::ssr::render_lazy(rsx!{
let output = dioxus_ssr::render_lazy(rsx!{
div {
RenderContent { content: all_content }
}
+2 -2
View File
@@ -24,7 +24,7 @@ cargo install --git https://github.com/BrainiumLLC/cargo-mobile
And then initialize your app for the right platform. Use the `winit` template for now. Right now, there's no "Dioxus" template in cargo-mobile.
```shell
cargo mobile init
cargo mobile init
```
We're going to completely clear out the `dependencies` it generates for us, swapping out `winit` with `dioxus-mobile`.
@@ -61,7 +61,7 @@ Edit your `lib.rs`:
use dioxus::prelude::*;
fn main() {
dioxus::mobile::launch(app);
dioxus_mobile::launch(app);
}
fn app(cx: Scope) -> Element {
+4 -4
View File
@@ -21,10 +21,10 @@ If you just want to render `rsx!` or a VirtualDom to HTML, check out the API doc
// We can render VirtualDoms
let mut vdom = VirtualDom::new(app);
let _ = vdom.rebuild();
println!("{}", dioxus::ssr::render_vdom(&vdom));
println!("{}", dioxus_ssr::render_vdom(&vdom));
// Or we can render rsx! calls directly
println!( "{}", dioxus::ssr::render_lazy(rsx! { h1 { "Hello, world!" } } );
println!( "{}", dioxus_ssr::render_lazy(rsx! { h1 { "Hello, world!" } } );
```
However, for this guide, we're going to show how to use Dioxus SSR with `Axum`.
@@ -84,7 +84,7 @@ And then add our endpoint. We can either render `rsx!` directly:
```rust
async fn app_endpoint() -> Html<String> {
Html(dioxus::ssr::render_lazy(rsx! {
Html(dioxus_ssr::render_lazy(rsx! {
h1 { "hello world!" }
}))
}
@@ -100,7 +100,7 @@ async fn app_endpoint() -> Html<String> {
let mut app = VirtualDom::new(app);
let _ = app.rebuild();
Html(dioxus::ssr::render_vdom(&app))
Html(dioxus_ssr::render_vdom(&app))
}
```
+1 -1
View File
@@ -1,3 +1,3 @@
# Interactivity
So far, we've learned how to describe the structure and properties of our user interfaces. However, most interfaces need to be interactive in order to be useful. In this chapter, we describe how to make a Dioxus app that responds to the user.
So far, we've learned how to describe the structure and properties of our user interfaces. However, most interfaces need to be interactive in order to be useful. In this chapter, we describe how to make a Dioxus app that responds to the user.