nova_forms/hooks/
nova_forms_use.rs1use leptos::*;
2
3#[macro_export]
5macro_rules! wire {
6 ( move | $($input:ident),* | $($t:tt)* ) => {
7 {
8 $(
9 let $input = leptos::create_signal(Default::default());
10 )*
11
12 let output = leptos::Signal::derive(move || {
13 (|$($input),*| {
14 $($t)*
15 })($($input.0.get()),*)
16 });
17
18 (output, $( $input.1 ),*)
19 }
20 };
21}
22
23pub fn on_ok<F, T, E>(f: F) -> impl Fn(Result<T, E>)
25where
26 F: Fn(T) + 'static,
27{
28 move |result| {
29 if let Ok(t) = result {
30 f(t)
31 }
32 }
33}
34
35pub fn on_err<F, T, E>(f: F) -> impl Fn(Result<T, E>)
37where
38 F: Fn(E) + 'static,
39{
40 move |result| {
41 if let Err(err) = result {
42 f(err)
43 }
44 }
45}
46
47pub fn set<T, S>(signal: S) -> impl Fn(T)
49where
50 S: SignalSet<Value = T>,
51{
52 move |t| {
53 signal.set(t);
54 }
55}
56