mirror of
https://github.com/adoyle0/thaw.git
synced 2025-02-03 00:54:15 -05:00
30 lines
604 B
Rust
30 lines
604 B
Rust
use leptos::{create_rw_signal, RwSignal, SignalGetUntracked, SignalSet};
|
|
|
|
pub struct ComponentRef<T: 'static>(RwSignal<Option<T>>);
|
|
|
|
impl<T> Default for ComponentRef<T> {
|
|
fn default() -> Self {
|
|
Self(create_rw_signal(None))
|
|
}
|
|
}
|
|
|
|
impl<T> Clone for ComponentRef<T> {
|
|
fn clone(&self) -> Self {
|
|
*self
|
|
}
|
|
}
|
|
|
|
impl<T: 'static> Copy for ComponentRef<T> {}
|
|
|
|
impl<T> ComponentRef<T> {
|
|
pub fn get_untracked(&self) -> Option<T>
|
|
where
|
|
T: Clone,
|
|
{
|
|
self.0.get_untracked()
|
|
}
|
|
|
|
pub fn load(&self, comp_ref: T) {
|
|
self.0.set(Some(comp_ref));
|
|
}
|
|
}
|