pub trait Observed {
// Required method
fn changed(self: Rc<Self>);
}Expand description
A trait to be notified when the state value changes.
Currently, only Slices and Atoms can be observed. This API may be expanded to other state types in the future.
§Example
use bounce::prelude::*;
use std::rc::Rc;
#[derive(Atom, PartialEq, Default)]
#[bounce(observed)] // observed states need to be denoted with the observed attribute.
struct State {
value: usize,
}
impl Observed for State {
fn changed(self: Rc<Self>) {
// this method will be called when the value of the state changes.
}
}