This commit is contained in:
Greg Johnston 2024-03-11 09:32:14 -04:00
parent abfe3cabd2
commit 30c1cd921b
7 changed files with 60 additions and 16 deletions

View File

@ -1,3 +1,3 @@
#[unstable]
#build-std = ["std", "panic_abort", "core", "alloc"]
#build-std-features = ["panic_immediate_abort"]
[unstable]
build-std = ["std", "panic_abort", "core", "alloc"]
build-std-features = ["panic_immediate_abort"]

View File

@ -12,8 +12,8 @@ panic = "abort"
[dependencies]
console_log = "1"
log = "0.4"
leptos = { path = "../../leptos", features = ["csr", "tracing"] }
routing = { path = "../../routing", features = ["tracing"] }
leptos = { path = "../../leptos", features = ["csr"] } #, "tracing"] }
routing = { path = "../../routing" } #, features = ["tracing"] }
#leptos_router = { path = "../../router", features = ["csr", "nightly"] }
serde = { version = "1", features = ["derive"] }
futures = "0.3"

View File

@ -4,13 +4,13 @@ use tracing_subscriber::fmt;
use tracing_subscriber_wasm::MakeConsoleWriter;
pub fn main() {
fmt()
/* fmt()
.with_writer(
MakeConsoleWriter::default()
.map_trace_level_to(tracing::Level::DEBUG),
)
.without_time()
.init();
console_error_panic_hook::set_once();
console_error_panic_hook::set_once();*/
mount_to_body(RouterExample);
}

View File

@ -44,13 +44,11 @@ default = ["serde"]
csr = [
"leptos_macro/csr",
"leptos_reactive/csr",
"leptos_server/csr",
"dep:wasm-bindgen",
]
hydrate = [
"leptos_macro/hydrate",
"leptos_reactive/hydrate",
"leptos_server/hydrate",
"dep:wasm-bindgen",
]
default-tls = ["leptos_server/default-tls", "server_fn/default-tls"]
@ -58,14 +56,12 @@ rustls = ["leptos_server/rustls", "server_fn/rustls"]
ssr = [
"leptos_macro/ssr",
"leptos_reactive/ssr",
"leptos_server/ssr",
"server_fn/ssr",
]
nightly = [
"leptos_dom/nightly",
"leptos_macro/nightly",
"leptos_reactive/nightly",
"leptos_server/nightly",
"tachys/nightly",
]
serde = ["leptos_reactive/serde"]

View File

@ -10,7 +10,7 @@ readme = "../README.md"
rust-version.workspace = true
[dependencies]
leptos_reactive = { workspace = true }
reactive_graph = { workspace = true }
leptos_macro = { workspace = true }
server_fn = { workspace = true }
lazy_static = "1"
@ -23,12 +23,8 @@ inventory = "0.3"
leptos = { path = "../leptos" }
[features]
csr = ["leptos_reactive/csr", "leptos_macro/csr"]
default-tls = ["server_fn/default-tls"]
hydrate = ["leptos_reactive/hydrate", "leptos_macro/hydrate"]
rustls = ["server_fn/rustls"]
ssr = ["leptos_reactive/ssr", "server_fn/ssr", "leptos_macro/ssr"]
nightly = ["leptos_reactive/nightly"]
[package.metadata.cargo-all-features]
denylist = ["nightly"]

View File

@ -0,0 +1,51 @@
use crate::{
computed::AsyncState,
signal::ArcRwSignal,
traits::{Set, Update},
};
use std::{
future::Future,
pin::Pin,
sync::{atomic::AtomicUsize, Arc},
};
pub enum ActionState<I, O> {
Idle,
Loading(I),
Complete(O),
Reloading(I, O),
}
pub struct ArcAction<I, O>
where
I: 'static,
O: 'static,
{
version: ArcRwSignal<usize>,
state: ArcRwSignal<ActionState<I, O>>,
pending_dispatches: Arc<AtomicUsize>,
#[allow(clippy::complexity)]
action_fn: Arc<dyn Fn(&I) -> Pin<Box<dyn Future<Output = O>>>>,
#[cfg(debug_assertion)]
defined_at: &'static Location<'static>,
}
impl<I, O> ArcAction<I, O>
where
I: 'static,
O: 'static,
{
#[track_caller]
pub fn dispatch(&self, input: I) {
let fut = (self.action_fn)(&input);
self.state.update(|prev| {
*prev = match prev {
ActionState::Idle => ActionState::Loading(input),
ActionState::Loading(_) => todo!(),
ActionState::Complete(_) => todo!(),
ActionState::Reloading(_, _) => todo!(),
}
});
}
}

View File

@ -72,6 +72,7 @@
use futures::Stream;
use std::{future::Future, pin::Pin};
pub mod action;
pub(crate) mod channel;
pub mod computed;
pub mod diagnostics;