pub struct Expr<T> { /* private fields */ }Expand description
A value with a JavaScript expression that can produce it in the browser.
Expressions that read no signals render as static content. Their JavaScript remains available when needed for browser execution.
Implementations§
Source§impl<T> Expr<T>
impl<T> Expr<T>
Sourcepub fn evaluate(evaluate: impl FnOnce() -> T, js: Js) -> Self
pub fn evaluate(evaluate: impl FnOnce() -> T, js: Js) -> Self
Evaluates an expression while observing signal reads.
The evaluation is synchronous. Its signal reads must represent the dependencies of the JavaScript expression as well.
Sourcepub fn is_static(&self) -> bool
pub fn is_static(&self) -> bool
Whether this expression is known not to require reactive evaluation.
Signal reads during evaluate make it dynamic.
Sourcepub fn dynamic(self) -> Self
pub fn dynamic(self) -> Self
Makes this expression dynamic even if it reads no signals.
A static expression only renders its value. A dynamic one is also evaluated in the browser whenever its content renders. As a bind attribute, this sets the element’s live state on every render, such as the value of an input the user has edited, instead of only its default.
use topcoat::{Result, context::Cx, runtime::Expr, view::*};
#[component]
async fn search(cx: &Cx) -> Result<impl View> {
// Every render clears what the user typed.
let query = Expr::from(String::new()).dynamic();
Ok(view! { <input :value=(query)> })
}Sourcepub fn into_evaluated_and_js(self) -> (T, Js)
pub fn into_evaluated_and_js(self) -> (T, Js)
Returns the value and its JavaScript, including for static expressions.