nova_forms/hooks/
nova_forms_use.rs

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
use leptos::*;

#[macro_export]
macro_rules! wire {
    ( move | $($input:ident),* | $($t:tt)* ) => {
        {
            $(
                let $input = leptos::create_signal(Default::default());
            )*

            let output = leptos::Signal::derive(move || {
                (|$($input),*| {
                    $($t)*
                })($($input.0.get()),*)
            });

            (output, $( $input.1 ),*)
        }  
    };
}


pub fn on_ok<F, T, E>(f: F) -> impl Fn(Result<T, E>)
where
    F: Fn(T) + 'static,
{
    move |result| {
        if let Ok(t) = result {
            f(t)
        }
    }   
}

pub fn on_err<F, T, E>(f: F) -> impl Fn(Result<T, E>)
where
    F: Fn(E) + 'static,
{
    move |result| {
        if let Err(err) = result {
            f(err)
        }
    }   
}


pub fn set<T, S>(signal: S) -> impl Fn(T)
where
    S: SignalSet<Value = T>,
{
    move |t| {
        signal.set(t);
    }   
}