1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Subsecond integration helpers.
#[cfg(feature = "subsecond")]
mod imp {
pub use dioxus_devtools::subsecond::{HotFn, HotFunction, call, register_handler};
/// Returns whether the Subsecond integration should run.
#[inline]
pub const fn enabled() -> bool {
cfg!(debug_assertions)
}
/// Runs a generated static render continuation through Subsecond.
#[inline]
pub fn hot_call<A, M, F>(f: F, args: A) -> F::Return
where
F: HotFunction<A, M>,
{
let mut hot = HotFn::current(f);
hot.call(args)
}
/// Runs a generated one-argument render continuation through Subsecond.
///
/// The explicit `FnMut(A)` bound keeps closure-argument types inferable for generated
/// tuple-argument render bodies.
#[inline]
pub fn hot_call_with_arg<A, M, F>(f: F, arg: A) -> F::Return
where
F: FnMut(A) + HotFunction<(A,), M>,
{
hot_call(f, (arg,))
}
/// Connect this process to a Dioxus/Subsecond devserver when one is available.
///
/// `cargo cheers subsecond` runs the app under `dx serve --hot-patch`, which sets
/// the `DIOXUS_DEVSERVER_*` environment variables consumed by this function.
/// Calling it when no devserver is present is harmless.
pub fn connect() {
dioxus_devtools::connect_subsecond();
}
}
#[cfg(not(feature = "subsecond"))]
mod imp {
/// Returns whether the Subsecond integration should run.
#[inline]
pub const fn enabled() -> bool {
false
}
/// Runs a generated render body directly when Subsecond is not compiled in.
#[inline]
pub fn call<O>(mut f: impl FnMut() -> O) -> O {
f()
}
/// Calls a generated static render continuation directly when Subsecond is not compiled in.
#[inline]
pub fn hot_call<A, O>(f: impl FnOnce(A) -> O, args: (A,)) -> O {
f(args.0)
}
/// Calls a generated one-argument render continuation directly when Subsecond is not compiled in.
#[inline]
pub fn hot_call_with_arg<A, O>(mut f: impl FnMut(A) -> O, arg: A) -> O {
f(arg)
}
/// Registers a callback that runs after a Subsecond patch is applied.
#[inline]
pub fn register_handler(_handler: std::sync::Arc<dyn Fn() + Send + Sync + 'static>) {}
/// Does nothing when Subsecond is not compiled in.
#[inline]
pub fn connect() {}
}
pub use imp::*;