💥 Rename Pack to MixComponents

This commit is contained in:
Manuel Cillero 2023-08-17 23:52:22 +02:00
parent 6197052ae7
commit 24f2f0d765
9 changed files with 52 additions and 52 deletions

View file

@ -12,7 +12,7 @@ pub struct Block {
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
title : AttributeValue, title : AttributeValue,
stuff : PackComponents, stuff : MixComponents,
template : String, template : String,
} }
@ -94,12 +94,12 @@ impl Block {
} }
pub fn with_component(mut self, component: impl ComponentTrait) -> Self { pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter(PackOp::Add(ComponentArc::with(component))); self.stuff.alter(MixOp::Add(ComponentArc::with(component)));
self self
} }
#[fn_builder] #[fn_builder]
pub fn alter_components(&mut self, op: PackOp) -> &mut Self { pub fn alter_components(&mut self, op: MixOp) -> &mut Self {
self.stuff.alter(op); self.stuff.alter(op);
self self
} }
@ -120,7 +120,7 @@ impl Block {
&self.title &self.title
} }
pub fn components(&self) -> &PackComponents { pub fn components(&self) -> &MixComponents {
&self.stuff &self.stuff
} }

View file

@ -23,7 +23,7 @@ pub struct Container {
classes : Classes, classes : Classes,
inner_classes : Classes, inner_classes : Classes,
container_type: ContainerType, container_type: ContainerType,
stuff : PackComponents, stuff : MixComponents,
template : String, template : String,
} }
@ -155,12 +155,12 @@ impl Container {
} }
pub fn with_component(mut self, component: impl ComponentTrait) -> Self { pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter(PackOp::Add(ComponentArc::with(component))); self.stuff.alter(MixOp::Add(ComponentArc::with(component)));
self self
} }
#[fn_builder] #[fn_builder]
pub fn alter_components(&mut self, op: PackOp) -> &mut Self { pub fn alter_components(&mut self, op: MixOp) -> &mut Self {
self.stuff.alter(op); self.stuff.alter(op);
self self
} }
@ -185,7 +185,7 @@ impl Container {
&self.container_type &self.container_type
} }
pub fn components(&self) -> &PackComponents { pub fn components(&self) -> &MixComponents {
&self.stuff &self.stuff
} }

View file

@ -44,7 +44,7 @@ pub struct Item {
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
size : ItemSize, size : ItemSize,
stuff : PackComponents, stuff : MixComponents,
template : String, template : String,
} }
@ -136,12 +136,12 @@ impl Item {
} }
pub fn with_component(mut self, component: impl ComponentTrait) -> Self { pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter(PackOp::Add(ComponentArc::with(component))); self.stuff.alter(MixOp::Add(ComponentArc::with(component)));
self self
} }
#[fn_builder] #[fn_builder]
pub fn alter_components(&mut self, op: PackOp) -> &mut Self { pub fn alter_components(&mut self, op: MixOp) -> &mut Self {
self.stuff.alter(op); self.stuff.alter(op);
self self
} }
@ -162,7 +162,7 @@ impl Item {
&self.size &self.size
} }
pub fn components(&self) -> &PackComponents { pub fn components(&self) -> &MixComponents {
&self.stuff &self.stuff
} }

View file

@ -21,7 +21,7 @@ pub struct Form {
action : AttributeValue, action : AttributeValue,
charset : AttributeValue, charset : AttributeValue,
method : FormMethod, method : FormMethod,
stuff : PackComponents, stuff : MixComponents,
template : String, template : String,
} }
@ -121,12 +121,12 @@ impl Form {
} }
pub fn with_element(mut self, element: impl ComponentTrait) -> Self { pub fn with_element(mut self, element: impl ComponentTrait) -> Self {
self.stuff.alter(PackOp::Add(ComponentArc::with(element))); self.stuff.alter(MixOp::Add(ComponentArc::with(element)));
self self
} }
#[fn_builder] #[fn_builder]
pub fn alter_elements(&mut self, op: PackOp) -> &mut Self { pub fn alter_elements(&mut self, op: MixOp) -> &mut Self {
self.stuff.alter(op); self.stuff.alter(op);
self self
} }
@ -155,7 +155,7 @@ impl Form {
&self.method &self.method
} }
pub fn elements(&self) -> &PackComponents { pub fn elements(&self) -> &MixComponents {
&self.stuff &self.stuff
} }

View file

@ -44,7 +44,7 @@ pub struct Column {
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
size : ColumnSize, size : ColumnSize,
stuff : PackComponents, stuff : MixComponents,
template : String, template : String,
} }
@ -136,12 +136,12 @@ impl Column {
} }
pub fn with_component(mut self, component: impl ComponentTrait) -> Self { pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter(PackOp::Add(ComponentArc::with(component))); self.stuff.alter(MixOp::Add(ComponentArc::with(component)));
self self
} }
#[fn_builder] #[fn_builder]
pub fn alter_components(&mut self, op: PackOp) -> &mut Self { pub fn alter_components(&mut self, op: MixOp) -> &mut Self {
self.stuff.alter(op); self.stuff.alter(op);
self self
} }
@ -162,7 +162,7 @@ impl Column {
&self.size &self.size
} }
pub fn components(&self) -> &PackComponents { pub fn components(&self) -> &MixComponents {
&self.stuff &self.stuff
} }

View file

@ -20,7 +20,7 @@ pub struct Paragraph {
renderable: Renderable, renderable: Renderable,
id : IdentifierValue, id : IdentifierValue,
classes : Classes, classes : Classes,
stuff : PackComponents, stuff : MixComponents,
display : ParagraphDisplay, display : ParagraphDisplay,
template : String, template : String,
} }
@ -90,12 +90,12 @@ impl Paragraph {
} }
pub fn with_component(mut self, component: impl ComponentTrait) -> Self { pub fn with_component(mut self, component: impl ComponentTrait) -> Self {
self.stuff.alter(PackOp::Add(ComponentArc::with(component))); self.stuff.alter(MixOp::Add(ComponentArc::with(component)));
self self
} }
#[fn_builder] #[fn_builder]
pub fn alter_components(&mut self, op: PackOp) -> &mut Self { pub fn alter_components(&mut self, op: MixOp) -> &mut Self {
self.stuff.alter(op); self.stuff.alter(op);
self self
} }
@ -130,7 +130,7 @@ impl Paragraph {
&self.classes &self.classes
} }
pub fn components(&self) -> &PackComponents { pub fn components(&self) -> &MixComponents {
&self.stuff &self.stuff
} }

View file

@ -11,8 +11,8 @@ pub use renderable::{FnIsRenderable, Renderable};
mod arc; mod arc;
pub use arc::ComponentArc; pub use arc::ComponentArc;
mod pack; mod mix;
pub use pack::{PackComponents, PackOp}; pub use mix::{MixComponents, MixOp};
mod one; mod one;
pub use one::ComponentOne; pub use one::ComponentOne;

View file

@ -2,7 +2,7 @@ use crate::core::component::{ComponentArc, Context};
use crate::html::{html, Markup}; use crate::html::{html, Markup};
use crate::Handle; use crate::Handle;
pub enum PackOp { pub enum MixOp {
Add(ComponentArc), Add(ComponentArc),
AddAfterId(&'static str, ComponentArc), AddAfterId(&'static str, ComponentArc),
AddBeforeId(&'static str, ComponentArc), AddBeforeId(&'static str, ComponentArc),
@ -13,51 +13,51 @@ pub enum PackOp {
} }
#[derive(Clone, Default)] #[derive(Clone, Default)]
pub struct PackComponents(Vec<ComponentArc>); pub struct MixComponents(Vec<ComponentArc>);
impl PackComponents { impl MixComponents {
pub fn new() -> Self { pub fn new() -> Self {
PackComponents::default() MixComponents::default()
} }
pub fn with(arc: ComponentArc) -> Self { pub fn with(arc: ComponentArc) -> Self {
let mut pack = PackComponents::new(); let mut pack = MixComponents::new();
pack.alter(PackOp::Add(arc)); pack.alter(MixOp::Add(arc));
pack pack
} }
pub(crate) fn merge(packs: &[Option<&PackComponents>]) -> Self { pub(crate) fn merge(packs: &[Option<&MixComponents>]) -> Self {
let mut pack = PackComponents::default(); let mut pack = MixComponents::default();
for p in packs.iter().flatten() { for p in packs.iter().flatten() {
pack.0.append(&mut p.0.clone()); pack.0.append(&mut p.0.clone());
} }
pack pack
} }
// PackComponents BUILDER. // MixComponents BUILDER.
pub fn alter(&mut self, op: PackOp) -> &mut Self { pub fn alter(&mut self, op: MixOp) -> &mut Self {
match op { match op {
PackOp::Add(arc) => self.0.push(arc), MixOp::Add(arc) => self.0.push(arc),
PackOp::AddAfterId(id, arc) => { MixOp::AddAfterId(id, arc) => {
match self.0.iter().position(|c| c.id().as_deref() == Some(id)) { match self.0.iter().position(|c| c.id().as_deref() == Some(id)) {
Some(index) => self.0.insert(index + 1, arc), Some(index) => self.0.insert(index + 1, arc),
_ => self.0.push(arc), _ => self.0.push(arc),
} }
} }
PackOp::AddBeforeId(id, arc) => { MixOp::AddBeforeId(id, arc) => {
match self.0.iter().position(|c| c.id().as_deref() == Some(id)) { match self.0.iter().position(|c| c.id().as_deref() == Some(id)) {
Some(index) => self.0.insert(index, arc), Some(index) => self.0.insert(index, arc),
_ => self.0.insert(0, arc), _ => self.0.insert(0, arc),
} }
} }
PackOp::AddFirst(arc) => self.0.insert(0, arc), MixOp::AddFirst(arc) => self.0.insert(0, arc),
PackOp::RemoveById(id) => { MixOp::RemoveById(id) => {
if let Some(index) = self.0.iter().position(|c| c.id().as_deref() == Some(id)) { if let Some(index) = self.0.iter().position(|c| c.id().as_deref() == Some(id)) {
self.0.remove(index); self.0.remove(index);
} }
} }
PackOp::ReplaceById(id, arc) => { MixOp::ReplaceById(id, arc) => {
for c in self.0.iter_mut() { for c in self.0.iter_mut() {
if c.id().as_deref() == Some(id) { if c.id().as_deref() == Some(id) {
*c = arc; *c = arc;
@ -65,12 +65,12 @@ impl PackComponents {
} }
} }
} }
PackOp::Reset => self.0.clear(), MixOp::Reset => self.0.clear(),
} }
self self
} }
// PackComponents GETTERS. // MixComponents GETTERS.
pub fn get_by_id(&self, id: &'static str) -> Option<&ComponentArc> { pub fn get_by_id(&self, id: &'static str) -> Option<&ComponentArc> {
self.0.iter().find(|&c| c.id().as_deref() == Some(id)) self.0.iter().find(|&c| c.id().as_deref() == Some(id))
@ -84,7 +84,7 @@ impl PackComponents {
self.0.iter().filter(move |&c| c.handle() == handle) self.0.iter().filter(move |&c| c.handle() == handle)
} }
// PackComponents PREPARE. // MixComponents PREPARE.
pub fn prepare(&self, cx: &mut Context) -> Markup { pub fn prepare(&self, cx: &mut Context) -> Markup {
let mut components = self.0.clone(); let mut components = self.0.clone();

View file

@ -1,4 +1,4 @@
use crate::core::component::{ComponentArc, PackComponents, PackOp}; use crate::core::component::{ComponentArc, MixComponents, MixOp};
use crate::core::theme::ThemeRef; use crate::core::theme::ThemeRef;
use crate::{Handle, LazyStatic}; use crate::{Handle, LazyStatic};
@ -12,7 +12,7 @@ static COMMON_REGIONS: LazyStatic<RwLock<ComponentsRegions>> =
LazyStatic::new(|| RwLock::new(ComponentsRegions::new())); LazyStatic::new(|| RwLock::new(ComponentsRegions::new()));
#[derive(Default)] #[derive(Default)]
pub struct ComponentsRegions(HashMap<&'static str, PackComponents>); pub struct ComponentsRegions(HashMap<&'static str, MixComponents>);
impl ComponentsRegions { impl ComponentsRegions {
pub fn new() -> Self { pub fn new() -> Self {
@ -27,18 +27,18 @@ impl ComponentsRegions {
pub fn add_in(&mut self, region: &'static str, arc: ComponentArc) { pub fn add_in(&mut self, region: &'static str, arc: ComponentArc) {
if let Some(region) = self.0.get_mut(region) { if let Some(region) = self.0.get_mut(region) {
region.alter(PackOp::Add(arc)); region.alter(MixOp::Add(arc));
} else { } else {
self.0.insert(region, PackComponents::with(arc)); self.0.insert(region, MixComponents::with(arc));
} }
} }
pub fn get_components(&self, theme: ThemeRef, region: &str) -> PackComponents { pub fn get_components(&self, theme: ThemeRef, region: &str) -> MixComponents {
let common = COMMON_REGIONS.read().unwrap(); let common = COMMON_REGIONS.read().unwrap();
if let Some(hm) = THEME_REGIONS.read().unwrap().get(&theme.handle()) { if let Some(hm) = THEME_REGIONS.read().unwrap().get(&theme.handle()) {
PackComponents::merge(&[common.0.get(region), self.0.get(region), hm.0.get(region)]) MixComponents::merge(&[common.0.get(region), self.0.get(region), hm.0.get(region)])
} else { } else {
PackComponents::merge(&[common.0.get(region), self.0.get(region)]) MixComponents::merge(&[common.0.get(region), self.0.get(region)])
} }
} }
} }