✨ Nuevos métodos para la API de bundles
This commit is contained in:
parent
7a6cb4dbfa
commit
bf3b546640
1 changed files with 24 additions and 2 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use crate::core::component::{ComponentTrait, RenderContext};
|
||||
use crate::fn_builder;
|
||||
use crate::html::{html, Markup};
|
||||
use crate::{fn_builder, Handle};
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
|
|
@ -14,8 +14,10 @@ pub enum BundleOp {
|
|||
Reset,
|
||||
}
|
||||
|
||||
pub type ArcLockComponent = Arc<RwLock<dyn ComponentTrait>>;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct ComponentsBundle(Vec<Arc<RwLock<dyn ComponentTrait>>>);
|
||||
pub struct ComponentsBundle(Vec<ArcLockComponent>);
|
||||
|
||||
impl ComponentsBundle {
|
||||
pub fn new() -> Self {
|
||||
|
|
@ -92,6 +94,26 @@ impl ComponentsBundle {
|
|||
self
|
||||
}
|
||||
|
||||
// ComponentsBundle GETTERS.
|
||||
|
||||
pub fn get_by_id(&self, id: &'static str) -> Option<&ArcLockComponent> {
|
||||
self.0
|
||||
.iter()
|
||||
.find(|&c| c.read().unwrap().id().as_deref() == Some(id))
|
||||
}
|
||||
|
||||
pub fn iter_by_id(&self, id: &'static str) -> impl Iterator<Item = &ArcLockComponent> {
|
||||
self.0
|
||||
.iter()
|
||||
.filter(|&c| c.read().unwrap().id().as_deref() == Some(id))
|
||||
}
|
||||
|
||||
pub fn iter_by_handle(&self, handle: Handle) -> impl Iterator<Item = &ArcLockComponent> {
|
||||
self.0
|
||||
.iter()
|
||||
.filter(move |&c| c.read().unwrap().handle() == handle)
|
||||
}
|
||||
|
||||
// ComponentsBundle RENDER.
|
||||
|
||||
pub fn render(&self, rcx: &mut RenderContext) -> Markup {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue