Skip to content

Commit

Permalink
Merge branch 'main' into fullstack-context
Browse files Browse the repository at this point in the history
  • Loading branch information
ealmloff committed Jun 19, 2024
2 parents 08433f7 + 7ee3dc4 commit 6c26ffc
Show file tree
Hide file tree
Showing 46 changed files with 1,318 additions and 559 deletions.
14 changes: 7 additions & 7 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ Steps to reproduce the behavior:

**Expected behavior**

A clear and concise description of what you expected to happen.
<!-- A clear and concise description of what you expected to happen. -->

**Screenshots**

If applicable, add screenshots to help explain your problem.
<!-- If applicable, add screenshots to help explain your problem. -->

**Environment:**
- Dioxus version: [e.g. v0.17, `master`]
- Rust version: [e.g. 1.43.0, `nightly`]
- OS info: [e.g. MacOS]
- App platform: [e.g. `web`, `desktop`]
- Dioxus version: <!-- e.g. v0.17, `master` -->
- Rust version: <!-- e.g. 1.43.0, `nightly` -->
- OS info: <!-- e.g. MacOS -->
- App platform: <!-- e.g. `web`, `desktop` -->

**Questionnaire**
<!-- If you feel up to the challenge, please check one of the boxes below: -->
- [ ] I'm interested in fixing this myself but don't know where to start
- [ ] I would like to fix and I have a solution
- [ ] I don't have time to fix this right now, but maybe later
- [ ] I don't have time to fix this right now, but maybe later
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,15 @@ tokio = { version = "1.16.1", features = ["full"] }
# To make most examples faster to compile, we split out assets and http-related stuff
# This trims off like 270 dependencies, leading to a significant speedup in compilation time
[features]
default = ["dioxus/desktop"]
default = ["desktop"]
desktop = ["dioxus/desktop"]
liveview = ["dioxus/liveview"]
fullstack = ["dioxus/fullstack"]
axum = ["dioxus/axum"]
server = ["dioxus/axum"]
web = ["dioxus/web"]
collect-assets = ["manganis"]
http = ["reqwest", "http-range"]
collect-assets = ["dep:manganis"]
http = ["dep:reqwest", "dep:http-range"]

[[example]]
name = "login_form"
Expand Down
65 changes: 65 additions & 0 deletions examples/router_resource.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//! Example: Updating components with use_resource
//! -----------------
//!
//! This example shows how to use use_reactive to update a component properly
//! when linking to it from the same component, when using use_resource

use dioxus::prelude::*;

#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Home {},
#[route("/blog/:id")]
Blog { id: i32 },
}

fn main() {
launch(App);
}

#[component]
fn App() -> Element {
rsx! {
Router::<Route> {}
}
}

#[component]
fn Blog(id: ReadOnlySignal<i32>) -> Element {
async fn future(n: i32) -> i32 {
n
}

// if you use the naive approach, the "Blog post {id}" below will never update when clicking links!
// let res = use_resource(move || future(id));

// the use_reactive hook is required to properly update when clicking links to this component, from this component
let res = use_resource(move || future(id()));

match res() {
Some(id) => rsx! {
div {
"Blog post {id}"
}
for i in 0..10 {
div {
Link { to: Route::Blog { id: i }, "Go to Blog {i}" }
}
}
},
None => rsx! {},
}
}

#[component]
fn Home() -> Element {
rsx! {
Link {
to: Route::Blog {
id: 0
},
"Go to blog"
}
}
}
2 changes: 1 addition & 1 deletion packages/cli-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ tauri-utils = { version = "=1.5.*", optional = true }

[features]
default = ["read-config"]
cli = ["tauri-bundler", "tauri-utils", "clap", "toml", "cargo_toml"]
cli = ["dep:tauri-bundler", "dep:tauri-utils", "dep:clap", "dep:toml", "dep:cargo_toml"]
read-config = []

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ openssl = { version = "0.10", features = ["vendored"] }

[features]
default = []
plugin = ["mlua"]
plugin = ["dep:mlua"]

[[bin]]
path = "src/main.rs"
Expand Down
164 changes: 30 additions & 134 deletions packages/config-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,137 +6,33 @@ use proc_macro::TokenStream;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;

#[proc_macro]
pub fn server_only(input: TokenStream) -> TokenStream {
if cfg!(any(feature = "ssr", feature = "liveview")) {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}

#[proc_macro]
pub fn client(input: TokenStream) -> TokenStream {
if cfg!(any(feature = "desktop", feature = "web")) {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}

#[proc_macro]
pub fn web(input: TokenStream) -> TokenStream {
if cfg!(feature = "web") {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}

#[proc_macro]
pub fn desktop(input: TokenStream) -> TokenStream {
if cfg!(feature = "desktop") {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}

#[proc_macro]
pub fn mobile(input: TokenStream) -> TokenStream {
if cfg!(feature = "mobile") {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}

#[proc_macro]
pub fn fullstack(input: TokenStream) -> TokenStream {
if cfg!(feature = "fullstack") {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}

#[proc_macro]
pub fn static_generation(input: TokenStream) -> TokenStream {
if cfg!(feature = "static-generation") {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}

#[proc_macro]
pub fn ssr(input: TokenStream) -> TokenStream {
if cfg!(feature = "ssr") {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}

#[proc_macro]
pub fn liveview(input: TokenStream) -> TokenStream {
if cfg!(feature = "liveview") {
let input = TokenStream2::from(input);
quote! {
#input
}
} else {
quote! {
{}
}
}
.into()
}
macro_rules! define_config_macro {
($name:ident if $($cfg:tt)+) => {
#[proc_macro]
pub fn $name(input: TokenStream) -> TokenStream {
if cfg!($($cfg)+) {
let input = TokenStream2::from(input);
quote! {
{
#input
}
}
} else {
quote! {
{}
}
}
.into()
}
};
}

define_config_macro!(server_only if any(feature = "ssr", feature = "liveview"));
define_config_macro!(client if any(feature = "desktop", feature = "web"));
define_config_macro!(web if feature = "web");
define_config_macro!(desktop if feature = "desktop");
define_config_macro!(mobile if feature = "mobile");
define_config_macro!(fullstack if feature = "fullstack");
define_config_macro!(static_generation if feature = "static-generation");
define_config_macro!(ssr if feature = "ssr");
define_config_macro!(liveview if feature = "liveview");
Loading

0 comments on commit 6c26ffc

Please sign in to comment.