VarSubscribe

Trait VarSubscribe 

Source
pub trait VarSubscribe<T: VarValue>: AnyVarSubscribe {
    // Required methods
    fn subscribe_when(
        &self,
        op: UpdateOp,
        widget_id: WidgetId,
        predicate: impl Fn(&T) -> bool + Send + Sync + 'static,
    ) -> VarHandle;
    fn on_pre_new(&self, handler: Handler<OnVarArgs<T>>) -> VarHandle;
    fn on_new(&self, handler: Handler<OnVarArgs<T>>) -> VarHandle;
}
Expand description

Extension methods to subscribe any widget to a variable or app handlers to a variable.

Also see WIDGET methods for the primary way to subscribe from inside a widget.

Required Methods§

Source

fn subscribe_when( &self, op: UpdateOp, widget_id: WidgetId, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> VarHandle

Register the widget to receive an UpdateOp when this variable is new and the predicate approves the new value.

Variables without the NEW capability return VarHandle::dummy.

Source

fn on_pre_new(&self, handler: Handler<OnVarArgs<T>>) -> VarHandle

Add a preview handler that is called every time this variable updates, the handler is called before UI update.

Note that the handler runs on the app context, all ContextVar<T> used inside will have the default value.

Source

fn on_new(&self, handler: Handler<OnVarArgs<T>>) -> VarHandle

Add a handler that is called every time this variable updates, the handler is called after UI update.

Note that the handler runs on the app context, all ContextVar<T> used inside will have the default value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: VarValue> VarSubscribe<T> for Var<T>

Source§

fn subscribe_when( &self, op: UpdateOp, widget_id: WidgetId, predicate: impl Fn(&T) -> bool + Send + Sync + 'static, ) -> VarHandle

Source§

fn on_pre_new(&self, handler: Handler<OnVarArgs<T>>) -> VarHandle

Source§

fn on_new(&self, handler: Handler<OnVarArgs<T>>) -> VarHandle

Implementors§