pub struct Effect(/* private fields */);Expand description
A reactive effect that re-runs when its dependencies change.
Effects are eager: when a dependency signal changes, the effect closure is re-run immediately. The effect also runs once on creation to discover its initial dependencies.
§Examples
ⓘ
let count = Signal::new(0);
let log = Rc::new(RefCell::new(Vec::new()));
let effect = Effect::new({
let count = count.clone();
let log = log.clone();
move || {
log.borrow_mut().push(count.get());
}
});
count.set(1); // effect re-runs, logs [0, 1]Implementations§
Source§impl Effect
impl Effect
Sourcepub fn new(f: impl FnMut() + 'static) -> Self
pub fn new(f: impl FnMut() + 'static) -> Self
Create a new effect that runs the given closure.
The closure is called immediately to discover dependencies. It will be re-called whenever any signal read during its execution changes.
Sourcepub fn dispose(&self)
pub fn dispose(&self)
Permanently deactivate this effect.
Once disposed, the effect will not run again even if its dependencies change.
Sourcepub fn subscriber_id(&self) -> SubscriberId
pub fn subscriber_id(&self) -> SubscriberId
Get this effect’s subscriber ID.
Sourcepub fn as_subscriber(&self) -> Weak<dyn Subscriber>
pub fn as_subscriber(&self) -> Weak<dyn Subscriber>
Get a weak reference suitable for subscribing to signals.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Effect
impl !RefUnwindSafe for Effect
impl !Send for Effect
impl !Sync for Effect
impl Unpin for Effect
impl !UnwindSafe for Effect
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more