Enum MaybeDyn
pub enum MaybeDyn<T>{
Static(T),
Signal(ReadSignal<T>),
Derived(Rc<dyn Fn() -> MaybeDyn<T>>),
}
Expand description
Represents a value that can be either static or dynamic.
This is useful for cases where you want to accept a value that can be either static or dynamic, such as in component props.
A MaybeDyn
value can be created from a static value or a closure that returns the value by
using the From
trait.
§Creating a MaybeDyn
You can create a MaybeDyn
from a static value by using the MaybeDyn::Static
variant.
However, most of the times, you probably want to use the implementation of the From<U>
trait
for MaybeDyn<T>
.
This trait is already implemented globally for signals and closures that return T
. However,
we cannot provide a blanket implementation for all types T
to convert into MaybeDyn<T>
because of specialization. Instead, we can only implement it for specific types.
Variants§
Static(T)
A static value.
Signal(ReadSignal<T>)
A dynamic value backed by a signal.
Derived(Rc<dyn Fn() -> MaybeDyn<T>>)
A derived dynamic value.
Implementations§
§impl<T> MaybeDyn<T>
impl<T> MaybeDyn<T>
pub fn evaluate(self) -> Twhere
T: Clone,
pub fn evaluate(self) -> Twhere
T: Clone,
Get the value by consuming itself. Unlike get_clone
, this method avoids
a clone if we are just storing a static value.
pub fn track(&self)
pub fn track(&self)
Track the reactive dependencies, if it is dynamic.
Trait Implementations§
§impl AttributeValue for MaybeDyn<JsValue>
impl AttributeValue for MaybeDyn<JsValue>
§impl AttributeValue for MaybeDyn<bool>
impl AttributeValue for MaybeDyn<bool>
§impl<T, U> From<ReadSignal<U>> for MaybeDyn<T>
impl<T, U> From<ReadSignal<U>> for MaybeDyn<T>
§fn from(val: ReadSignal<U>) -> MaybeDyn<T>
fn from(val: ReadSignal<U>) -> MaybeDyn<T>
Auto Trait Implementations§
impl<T> Freeze for MaybeDyn<T>where
T: Freeze,
impl<T> !RefUnwindSafe for MaybeDyn<T>
impl<T> !Send for MaybeDyn<T>
impl<T> !Sync for MaybeDyn<T>
impl<T> Unpin for MaybeDyn<T>where
T: Unpin,
impl<T> !UnwindSafe for MaybeDyn<T>
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)