From bf3b546640798be27c7d65ca08bf2e6d9cca4ae6 Mon Sep 17 00:00:00 2001 From: Manuel Cillero Date: Tue, 13 Jun 2023 22:15:14 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Nuevos=20m=C3=A9todos=20para=20la?= =?UTF-8?q?=20API=20de=20bundles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pagetop/src/core/component/bundle.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pagetop/src/core/component/bundle.rs b/pagetop/src/core/component/bundle.rs index 77f8cadf..06cba0a2 100644 --- a/pagetop/src/core/component/bundle.rs +++ b/pagetop/src/core/component/bundle.rs @@ -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>; + #[derive(Clone, Default)] -pub struct ComponentsBundle(Vec>>); +pub struct ComponentsBundle(Vec); 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 { + self.0 + .iter() + .filter(|&c| c.read().unwrap().id().as_deref() == Some(id)) + } + + pub fn iter_by_handle(&self, handle: Handle) -> impl Iterator { + self.0 + .iter() + .filter(move |&c| c.read().unwrap().handle() == handle) + } + // ComponentsBundle RENDER. pub fn render(&self, rcx: &mut RenderContext) -> Markup {