💥 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,
classes : Classes,
title : AttributeValue,
stuff : PackComponents,
stuff : MixComponents,
template : String,
}
@ -94,12 +94,12 @@ impl Block {
}
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
}
#[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
}
@ -120,7 +120,7 @@ impl Block {
&self.title
}
pub fn components(&self) -> &PackComponents {
pub fn components(&self) -> &MixComponents {
&self.stuff
}

View file

@ -23,7 +23,7 @@ pub struct Container {
classes : Classes,
inner_classes : Classes,
container_type: ContainerType,
stuff : PackComponents,
stuff : MixComponents,
template : String,
}
@ -155,12 +155,12 @@ impl Container {
}
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
}
#[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
}
@ -185,7 +185,7 @@ impl Container {
&self.container_type
}
pub fn components(&self) -> &PackComponents {
pub fn components(&self) -> &MixComponents {
&self.stuff
}

View file

@ -44,7 +44,7 @@ pub struct Item {
id : IdentifierValue,
classes : Classes,
size : ItemSize,
stuff : PackComponents,
stuff : MixComponents,
template : String,
}
@ -136,12 +136,12 @@ impl Item {
}
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
}
#[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
}
@ -162,7 +162,7 @@ impl Item {
&self.size
}
pub fn components(&self) -> &PackComponents {
pub fn components(&self) -> &MixComponents {
&self.stuff
}

View file

@ -21,7 +21,7 @@ pub struct Form {
action : AttributeValue,
charset : AttributeValue,
method : FormMethod,
stuff : PackComponents,
stuff : MixComponents,
template : String,
}
@ -121,12 +121,12 @@ impl Form {
}
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
}
#[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
}
@ -155,7 +155,7 @@ impl Form {
&self.method
}
pub fn elements(&self) -> &PackComponents {
pub fn elements(&self) -> &MixComponents {
&self.stuff
}

View file

@ -44,7 +44,7 @@ pub struct Column {
id : IdentifierValue,
classes : Classes,
size : ColumnSize,
stuff : PackComponents,
stuff : MixComponents,
template : String,
}
@ -136,12 +136,12 @@ impl Column {
}
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
}
#[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
}
@ -162,7 +162,7 @@ impl Column {
&self.size
}
pub fn components(&self) -> &PackComponents {
pub fn components(&self) -> &MixComponents {
&self.stuff
}

View file

@ -20,7 +20,7 @@ pub struct Paragraph {
renderable: Renderable,
id : IdentifierValue,
classes : Classes,
stuff : PackComponents,
stuff : MixComponents,
display : ParagraphDisplay,
template : String,
}
@ -90,12 +90,12 @@ impl Paragraph {
}
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
}
#[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
}
@ -130,7 +130,7 @@ impl Paragraph {
&self.classes
}
pub fn components(&self) -> &PackComponents {
pub fn components(&self) -> &MixComponents {
&self.stuff
}

View file

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

View file

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