pub type Scope<'a> = BoundedScope<'a, 'a>;
Implementations§
source§impl<'a> Scope<'a>
impl<'a> Scope<'a>
sourcepub fn new(f: impl FnOnce(Scope<'a>) + 'a) -> ScopeDisposer<'a>
pub fn new(f: impl FnOnce(Scope<'a>) + 'a) -> ScopeDisposer<'a>
Creates a new scope.
This function returns a ScopeDisposer
that must be used to dispose of the scope.
If the disposer is not used, the scope will leak memory.
sourcepub fn immediate(f: impl FnOnce(Scope<'a>) + 'a)
pub fn immediate(f: impl FnOnce(Scope<'a>) + 'a)
Creates a new scope and immediately disposes it.
sourcepub fn child(
self,
f: impl for<'b> FnOnce(BoundedScope<'b, 'a>)
) -> ScopeDisposer<'a>
pub fn child( self, f: impl for<'b> FnOnce(BoundedScope<'b, 'a>) ) -> ScopeDisposer<'a>
Creates a new child scope.
sourcepub unsafe fn alloc_unsafe<T: Sendable + 'a>(self, item: T) -> &'a T
pub unsafe fn alloc_unsafe<T: Sendable + 'a>(self, item: T) -> &'a T
sourcepub fn alloc_mut<T: Sendable + 'static>(&self, item: T) -> &'a mut T
pub fn alloc_mut<T: Sendable + 'static>(&self, item: T) -> &'a mut T
Allocates an item in the scope.
sourcepub unsafe fn alloc_mut_unsafe<T: Sendable + 'a>(self, item: T) -> &'a mut T
pub unsafe fn alloc_mut_unsafe<T: Sendable + 'a>(self, item: T) -> &'a mut T
sourcepub fn signal<T: SendSync + 'static>(self, value: T) -> &'a Signal<T>
pub fn signal<T: SendSync + 'static>(self, value: T) -> &'a Signal<T>
Creates a signal in the scope.
sourcepub fn untrack<T>(self, f: impl FnOnce() -> T) -> T
pub fn untrack<T>(self, f: impl FnOnce() -> T) -> T
Runs a scope without tracking any dependencies.
sourcepub fn effect(self, f: impl FnMut() + Sendable + 'a)
pub fn effect(self, f: impl FnMut() + Sendable + 'a)
Creates an effect.
Effects are callbacks that are run whenever a dependency changes (eg. a signal is updated).
Examples
let signal = cx.signal(0);
cx.effect(|| {
println!("signal is {}", signal.get()); // prints "signal is 0"
});
signal.set(1); // prints "signal is 1"
sourcepub fn effect_scoped(
self,
f: impl for<'b> FnMut(BoundedScope<'b, 'a>) + Sendable + 'a
)
pub fn effect_scoped( self, f: impl for<'b> FnMut(BoundedScope<'b, 'a>) + Sendable + 'a )
Creates an effect in a child scope. See Scope::effect
.
sourcepub fn memo<T: SendSync + 'static>(
self,
f: impl FnMut() -> T + Sendable + 'a
) -> &'a ReadSignal<T>
pub fn memo<T: SendSync + 'static>( self, f: impl FnMut() -> T + Sendable + 'a ) -> &'a ReadSignal<T>
Creates a signal that is recomputed every time a dependency is updated.
Examples
let signal = cx.signal(0);
let memo = cx.memo(|| *signal.get() * 2);
assert_eq!(*memo, 0);
signal.set(2);
assert_eq!(*memo, 4);
sourcepub fn bind<T: Clone + PartialEq + SendSync + 'static>(
self,
signal_a: &'a Signal<T>,
signal_b: &'a Signal<T>
)
pub fn bind<T: Clone + PartialEq + SendSync + 'static>( self, signal_a: &'a Signal<T>, signal_b: &'a Signal<T> )
This will create an effect that binds two signals together. Whenever one of the signals is updated, the other will be updated to the same value. This is useful for creating two-way bindings (eg. a checkbox).
When initializing the binding, the value of signal_b
will be used.
sourcepub fn dynamic<T: SendSync + 'static>(
self,
f: impl FnMut(BoundedScope<'_, 'a>) -> T + Sendable + 'a
) -> SharedSignal<T>
pub fn dynamic<T: SendSync + 'static>( self, f: impl FnMut(BoundedScope<'_, 'a>) -> T + Sendable + 'a ) -> SharedSignal<T>
Creates a shared signal that is recomputed every time a dependency is updated.