✨ Add component getter
This commit is contained in:
parent
33dff8f085
commit
0a03e293a2
2 changed files with 18 additions and 2 deletions
|
|
@ -2,7 +2,7 @@ use crate::core::component::{ComponentTrait, Context};
|
||||||
use crate::html::{html, Markup};
|
use crate::html::{html, Markup};
|
||||||
use crate::{new_handle, Handle, Weight};
|
use crate::{new_handle, Handle, Weight};
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock, RwLockReadGuard};
|
||||||
|
|
||||||
new_handle!(COMPONENT_NULL for Crate);
|
new_handle!(COMPONENT_NULL for Crate);
|
||||||
|
|
||||||
|
|
@ -37,10 +37,18 @@ impl ArcComponent {
|
||||||
ArcComponent(Arc::new(RwLock::new(component)))
|
ArcComponent(Arc::new(RwLock::new(component)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArcComponent BUILDER.
|
||||||
|
|
||||||
pub fn set(&mut self, component: impl ComponentTrait) {
|
pub fn set(&mut self, component: impl ComponentTrait) {
|
||||||
self.0 = Arc::new(RwLock::new(component));
|
self.0 = Arc::new(RwLock::new(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArcComponent GETTERS.
|
||||||
|
|
||||||
|
pub fn get(&self) -> RwLockReadGuard<'_, dyn ComponentTrait> {
|
||||||
|
self.0.read().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn handle(&self) -> Handle {
|
pub(crate) fn handle(&self) -> Handle {
|
||||||
self.0.read().unwrap().handle()
|
self.0.read().unwrap().handle()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::core::component::{ComponentTrait, Context};
|
||||||
use crate::html::{html, Markup};
|
use crate::html::{html, Markup};
|
||||||
use crate::{Handle, Weight};
|
use crate::{Handle, Weight};
|
||||||
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock, RwLockReadGuard};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct TypedComponent<T: ComponentTrait + Default>(Arc<RwLock<T>>);
|
pub struct TypedComponent<T: ComponentTrait + Default>(Arc<RwLock<T>>);
|
||||||
|
|
@ -22,10 +22,18 @@ impl<T: ComponentTrait + Default> TypedComponent<T> {
|
||||||
TypedComponent(Arc::new(RwLock::new(component)))
|
TypedComponent(Arc::new(RwLock::new(component)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TypedComponent BUILDER.
|
||||||
|
|
||||||
pub fn set(&mut self, component: T) {
|
pub fn set(&mut self, component: T) {
|
||||||
self.0 = Arc::new(RwLock::new(component));
|
self.0 = Arc::new(RwLock::new(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TypedComponent GETTERS.
|
||||||
|
|
||||||
|
pub fn get(&self) -> RwLockReadGuard<'_, T> {
|
||||||
|
self.0.read().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn handle(&self) -> Handle {
|
pub(crate) fn handle(&self) -> Handle {
|
||||||
self.0.read().unwrap().handle()
|
self.0.read().unwrap().handle()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue