🚧 Normaliza el uso de los bundles de componentes
This commit is contained in:
parent
b2a7c71c1f
commit
7a6cb4dbfa
9 changed files with 26 additions and 42 deletions
|
|
@ -254,14 +254,12 @@ impl MegaMenu {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_item(&mut self, item: MegaMenuItem) -> &mut Self {
|
||||
self.items.add(item);
|
||||
pub fn with_item(mut self, item: MegaMenuItem) -> Self {
|
||||
self.items.alter_bundle(BundleOp::Add, item);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, item: MegaMenuItem) -> &mut Self {
|
||||
pub fn alter_items(&mut self, op: BundleOp, item: MegaMenuItem) -> &mut Self {
|
||||
self.items.alter_bundle(op, item);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -158,14 +158,12 @@ impl Container {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.add(component);
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -124,14 +124,12 @@ impl Form {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_element(&mut self, element: impl ComponentTrait) -> &mut Self {
|
||||
self.elements.add(element);
|
||||
pub fn with_element(mut self, element: impl ComponentTrait) -> Self {
|
||||
self.elements.alter_bundle(BundleOp::Add, element);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, element: impl ComponentTrait) -> &mut Self {
|
||||
pub fn alter_elements(&mut self, op: BundleOp, element: impl ComponentTrait) -> &mut Self {
|
||||
self.elements.alter_bundle(op, element);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,14 +139,12 @@ impl Column {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.add(component);
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,14 +86,12 @@ impl Row {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_column(&mut self, column: grid::Column) -> &mut Self {
|
||||
self.columns.add(column);
|
||||
pub fn with_column(mut self, column: grid::Column) -> Self {
|
||||
self.columns.alter_bundle(BundleOp::Add, column);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, column: grid::Column) -> &mut Self {
|
||||
pub fn alter_columns(&mut self, op: BundleOp, column: grid::Column) -> &mut Self {
|
||||
self.columns.alter_bundle(op, column);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,14 +97,12 @@ impl Paragraph {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.add(component);
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,14 +97,12 @@ impl Block {
|
|||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_component(&mut self, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.add(component);
|
||||
pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
|
||||
self.components.alter_bundle(BundleOp::Add, component);
|
||||
self
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
pub fn alter_components(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
self.components.alter_bundle(op, component);
|
||||
self
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
use crate::core::component::{ComponentTrait, RenderContext};
|
||||
use crate::fn_builder;
|
||||
use crate::html::{html, Markup};
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
|
@ -23,7 +24,7 @@ impl ComponentsBundle {
|
|||
|
||||
pub fn new_with(component: impl ComponentTrait) -> Self {
|
||||
let mut bundle = ComponentsBundle::new();
|
||||
bundle.add(component);
|
||||
bundle.alter_bundle(BundleOp::Add, component);
|
||||
bundle
|
||||
}
|
||||
|
||||
|
|
@ -43,10 +44,7 @@ impl ComponentsBundle {
|
|||
|
||||
// ComponentsBundle BUILDER.
|
||||
|
||||
pub fn add(&mut self, component: impl ComponentTrait) -> &mut Self {
|
||||
self.alter_bundle(BundleOp::Add, component)
|
||||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_bundle(&mut self, op: BundleOp, component: impl ComponentTrait) -> &mut Self {
|
||||
let arc = Arc::new(RwLock::new(component));
|
||||
match op {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::core::component::{ComponentTrait, ComponentsBundle};
|
||||
use crate::core::component::{BundleOp, ComponentTrait, ComponentsBundle};
|
||||
use crate::LazyStatic;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -17,7 +17,7 @@ impl ComponentsRegions {
|
|||
|
||||
pub fn add_to(&mut self, region: &'static str, component: impl ComponentTrait) {
|
||||
if let Some(region) = self.0.get_mut(region) {
|
||||
region.add(component);
|
||||
region.alter_bundle(BundleOp::Add, component);
|
||||
} else {
|
||||
self.0.insert(region, ComponentsBundle::new_with(component));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue