🚚 Rename alter_...(...) functions to set_...(...)
This commit is contained in:
parent
dfb34d2e36
commit
fea6c2f69e
42 changed files with 314 additions and 312 deletions
|
|
@ -6,14 +6,14 @@ pub trait ComponentClassesOp {
|
|||
}
|
||||
|
||||
pub trait ComponentClasses: ComponentBase + ComponentClassesOp {
|
||||
fn alter_classes(&mut self, op: ClassesOp, classes: impl Into<String>) -> &mut Self;
|
||||
fn set_classes(&mut self, op: ClassesOp, classes: impl Into<String>) -> &mut Self;
|
||||
|
||||
fn classes(&self) -> &OptionClasses;
|
||||
}
|
||||
|
||||
impl<C: ComponentBase + ComponentClasses> ComponentClassesOp for C {
|
||||
fn with_classes(mut self, op: ClassesOp, classes: impl Into<String>) -> Self {
|
||||
self.alter_classes(op, classes);
|
||||
self.set_classes(op, classes);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ impl Context {
|
|||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
pub fn alter_assets(&mut self, op: AssetsOp) -> &mut Self {
|
||||
pub fn set_assets(&mut self, op: AssetsOp) -> &mut Self {
|
||||
match op {
|
||||
AssetsOp::LangId(langid) => {
|
||||
self.langid = langid;
|
||||
|
|
@ -116,8 +116,8 @@ impl Context {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn alter_regions(&mut self, region: &'static str, op: AnyOp) -> &mut Self {
|
||||
self.regions.alter_components(region, op);
|
||||
pub fn set_regions(&mut self, region: &'static str, op: AnyOp) -> &mut Self {
|
||||
self.regions.set_components(region, op);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ impl MixedComponents {
|
|||
// MixedComponents BUILDER.
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_value(&mut self, op: AnyOp) -> &mut Self {
|
||||
pub fn set_value(&mut self, op: AnyOp) -> &mut Self {
|
||||
match op {
|
||||
AnyOp::Add(any) => self.add(any),
|
||||
AnyOp::InsertAfterId(id, any) => self.insert_after_id(id, any),
|
||||
|
|
@ -116,7 +116,7 @@ impl MixedComponents {
|
|||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_typed<C: ComponentTrait + Default>(&mut self, op: TypedOp<C>) -> &mut Self {
|
||||
pub fn set_typed<C: ComponentTrait + Default>(&mut self, op: TypedOp<C>) -> &mut Self {
|
||||
match op {
|
||||
TypedOp::Add(typed) => self.add(typed.to_any()),
|
||||
TypedOp::InsertAfterId(id, typed) => self.insert_after_id(id, typed.to_any()),
|
||||
|
|
@ -164,7 +164,7 @@ impl MixedComponents {
|
|||
|
||||
#[inline]
|
||||
fn replace_by_id(&mut self, id: &str, any: AnyComponent) {
|
||||
for c in self.0.iter_mut() {
|
||||
for c in &mut self.0 {
|
||||
if c.id() == id {
|
||||
*c = any;
|
||||
break;
|
||||
|
|
@ -205,7 +205,7 @@ impl MixedComponents {
|
|||
|
||||
pub fn render(&self, cx: &mut Context) -> Markup {
|
||||
html! {
|
||||
@for c in self.0.iter() {
|
||||
@for c in &self.0 {
|
||||
(c.render(cx))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ pub trait ThemeTrait: PackageTrait + Send + Sync {
|
|||
|
||||
fn after_prepare_body(&self, page: &mut Page) {
|
||||
if page.favicon().is_none() {
|
||||
page.alter_favicon(Some(Favicon::new().with_icon("/base/favicon.ico")));
|
||||
page.set_favicon(Some(Favicon::new().with_icon("/base/favicon.ico")));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ impl ComponentsInRegions {
|
|||
}
|
||||
|
||||
#[fn_builder]
|
||||
pub fn alter_components(&mut self, region: &'static str, op: AnyOp) -> &mut Self {
|
||||
pub fn set_components(&mut self, region: &'static str, op: AnyOp) -> &mut Self {
|
||||
if let Some(region) = self.0.get_mut(region) {
|
||||
region.alter_value(op);
|
||||
region.set_value(op);
|
||||
} else {
|
||||
self.0.insert(region, MixedComponents::new().with_value(op));
|
||||
}
|
||||
|
|
@ -52,18 +52,18 @@ impl InRegion {
|
|||
COMMON_REGIONS
|
||||
.write()
|
||||
.unwrap()
|
||||
.alter_components("content", AnyOp::Add(any));
|
||||
.set_components("content", AnyOp::Add(any));
|
||||
}
|
||||
InRegion::Named(name) => {
|
||||
COMMON_REGIONS
|
||||
.write()
|
||||
.unwrap()
|
||||
.alter_components(name, AnyOp::Add(any));
|
||||
.set_components(name, AnyOp::Add(any));
|
||||
}
|
||||
InRegion::OfTheme(region, theme) => {
|
||||
let mut regions = THEME_REGIONS.write().unwrap();
|
||||
if let Some(r) = regions.get_mut(&theme.type_id()) {
|
||||
r.alter_components(region, AnyOp::Add(any));
|
||||
r.set_components(region, AnyOp::Add(any));
|
||||
} else {
|
||||
regions.insert(theme.type_id(), ComponentsInRegions::new(region, any));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue