euv-core 0.3.12

A declarative, cross-platform UI framework for Rust with virtual DOM, reactive signals, and HTML macros for WebAssembly.
Documentation
use crate::*;

/// Creates a reactive style `AttributeValue` that updates when signals change.
///
/// This function replaces the inline `Signal::new(...)` + `subscribe_attr_signal(...)`
/// boilerplate that was previously generated by the `html!` macro for every
/// `style:` attribute containing reactive `if` conditions.
///
/// # Arguments
///
/// - `Fn() -> String + 'static` - A closure that computes the current CSS string.
///   Called on initial render and whenever any signal changes.
///
/// # Returns
///
/// - `AttributeValue` - A `AttributeValue::Signal` backed by a `Signal<String>`
///   that reactively re-evaluates the CSS string on signal updates.
pub fn create_reactive_style_attribute<F>(compute: F) -> AttributeValue
where
    F: Fn() -> String + 'static,
{
    let attr_signal: Signal<String> = Signal::new(compute());
    subscribe_attr_signal(attr_signal, compute);
    AttributeValue::Signal(attr_signal)
}

/// Creates a reactive attribute `AttributeValue` for conditional attribute values.
///
/// This function replaces the inline `Signal::new(...)` + `subscribe_attr_signal(...)`
/// boilerplate that was previously generated by the `html!` macro for every
/// attribute value containing an `if` condition.
///
/// # Arguments
///
/// - `Fn() -> String + 'static` - A closure that computes the current attribute value.
///   Called on initial render and whenever any signal changes.
///
/// # Returns
///
/// - `AttributeValue` - A `AttributeValue::Signal` backed by a `Signal<String>`
///   that reactively re-evaluates the attribute value on signal updates.
pub fn create_reactive_attr_signal<F>(compute: F) -> AttributeValue
where
    F: Fn() -> String + 'static,
{
    let attr_signal: Signal<String> =
        Signal::new(IntoReactiveString::into_reactive_string(compute()));
    subscribe_attr_signal(attr_signal, move || {
        IntoReactiveString::into_reactive_string(compute())
    });
    AttributeValue::Signal(attr_signal)
}