pub fn double_bind<T>(self, var: T) -> Self
    where
        T: StateTrait + 'static,
        T::Value: FromStr + Default,
        T::Channel: Deref<Target = String>,
    {
        let elem = self.node.clone();
        let rx = var.rx();

        wasm_bindgen_futures::spawn_local(async move {
            let mut old = StateId::new();
            while let Some((new, value)) = rx.receive(old).await {
                elem.unchecked_ref::<web_sys::HtmlDataElement>()
                    .set_value(&value);
                old = new;
            }
        });

        self.bind(var)
    }
/// Two way bind to the input element.
/// Any change in the state variable will be reflected back to the input element.
///
/// # Examples
///
/// ```
/// # use valerie::prelude::*;
/// # use valerie::prelude::components::*;
/// # use wasm_bindgen_test::*;
/// # fn ui() -> Node {
/// let state = StateMutex::new(String::new());
/// div!(
///     state.clone(),
///     br!(),
///     input!("text").double_bind(state.clone()),
///     input!("text").double_bind(state)
/// )
/// # .into()
/// # }
/// # wasm_bindgen_test_configure!(run_in_browser);
/// # #[wasm_bindgen_test]
/// # fn run() {
/// #     App::render_single(ui());
/// # }
/// ```
Two way bind to the input element.
Any change in the state variable will be reflected back to the input element.
Two way bind to the input element . Any change in the state variable will be reflected back to the input element .
pub fn double_bind<T>(self, var: T) -> Self
    where
        T: StateTrait + 'static,
        T::Value: FromStr + Default,
        T::Channel: Deref<Target = String>,
    {
        let elem = self.node.clone();
        let rx = var.rx();
        wasm_bindgen_futures::spawn_local(async move {
            let mut old = StateId::new();
            while let Some((new, value)) = rx.receive(old).await {
                elem.unchecked_ref::<web_sys::HtmlDataElement>()
                    .set_value(&value);
                old = new;
            }
        });
        self.bind(var)
    }
pub fn double_bind < T > ( self , var : T ) -> Self where T : StateTrait + ' static , T :: Value : FromStr + Default , T :: Channel : Deref < Target = String > , { let elem = self . node . clone ( ) ; let rx = var . rx ( ) ; wasm_bindgen_futures :: spawn_local ( async move { let mut old = StateId :: new ( ) ; while let Some ( ( new , value ) ) = rx . receive ( old ) . await { elem . unchecked_ref :: < web_sys :: HtmlDataElement > ( ) . set_value ( & value ) ; old = new ; } } ) ; self . bind ( var ) }
Two way bind to the input element.
Two way bind to the input element .
self
var
T
examples
None
use valerie::prelude::*;
None
use valerie::prelude::components::*;
None
use wasm_bindgen_test::*;
None
fn ui() -> node {
let state = StateMutex::new(String::new());
div!(
state.clone(),
br!(),
input!("text").double_bind(state.clone()),
input!("text").double_bind(state)
)
let state = StateMutex :: new ( String :: new () ) ; div! ( state . clone () br! () input! ( " text " ) . double_bind ( state . clone () ) input! ( " text " ) . double_bind ( state ) )
.into()
None
}
None
wasm_bindgen_test_configure!(run_in_browser);
None
#[wasm_bindgen_test]
None
fn run() {
None
app::render_single(ui());
None
}
None