From 69ceb1f9ec68e41029759a6fcff3168adb6df373 Mon Sep 17 00:00:00 2001 From: jelemux Date: Thu, 4 Feb 2021 13:30:15 +0100 Subject: minor refactoring + comments --- src/view/address.rs | 19 ++++++++++++++++--- src/view/mod.rs | 6 ++++++ src/view/name.rs | 43 +++++++++++++++++++++---------------------- src/view/telephone.rs | 18 ++++++++++++++++-- 4 files changed, 59 insertions(+), 27 deletions(-) (limited to 'src/view') diff --git a/src/view/address.rs b/src/view/address.rs index a16d93a..01c949b 100644 --- a/src/view/address.rs +++ b/src/view/address.rs @@ -1,15 +1,28 @@ use yew::services::ConsoleService; +use yew::prelude::*; +use yewtil::NeqAssign; use yewtil::ptr::Irc; use yewtil::ptr::Mrc; use super::WeakComponentLink; -use yew::prelude::*; -use yewtil::NeqAssign; use crate::viewmodel::address::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; use crate::viewmodel::Error; - +/// View Component for a `address` field +/// +/// # Examples +/// +/// ```compile_fail +/// let html = html!{ +/// | +/// Msg::GeneratedAddress(some_address) +/// ) +/// /> +/// }; +/// ``` pub struct AddressView { props: Props, value: Mrc
, diff --git a/src/view/mod.rs b/src/view/mod.rs index 7a64fed..d97c6e4 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -9,10 +9,15 @@ pub mod name; pub mod address; pub mod telephone; +/// Trait for types that represent an input component for a vcard property. pub trait VCardPropertyInputComponent>: Component { + /// Returns the object containing the input data. fn get_input_object(&self) -> T; + /// Getter function for the title of the component fn get_title(&self) -> String; + /// Getter function for an eventual error. fn get_error(&self) -> Option; + /// Returns the error as `Html` fn render_error(&self) -> Html { html!{ <> @@ -32,6 +37,7 @@ pub trait VCardPropertyInputComponent>: Compon } } +/// Weak link; Useful for being able to have a list of subcomponents. pub struct WeakComponentLink(Rc>>>); impl Clone for WeakComponentLink { diff --git a/src/view/name.rs b/src/view/name.rs index 5b64bae..d864e35 100644 --- a/src/view/name.rs +++ b/src/view/name.rs @@ -1,14 +1,28 @@ use yew::services::ConsoleService; +use yew::prelude::*; +use yewtil::NeqAssign; use yewtil::ptr::Irc; use yewtil::ptr::Mrc; use crate::viewmodel::Error; use crate::view::WeakComponentLink; -use yew::prelude::*; -use yewtil::NeqAssign; use crate::viewmodel::name::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; +/// View Component for a `name` field +/// +/// # Examples +/// +/// ```compile_fail +/// let html = html!{ +/// | +/// Msg::GeneratedName(some_name) +/// ) +/// /> +/// }; +/// ``` pub struct NameView { props: Props, value: Mrc, @@ -62,26 +76,11 @@ impl Component for NameView { } fn update(&mut self, msg: ::Message) -> bool { match msg { - Msg::UpdatePrefix(p) => match self.value.get_mut() { - Some(value) => value.prefix = p, - None => ConsoleService::info("Couldn't get mutable reference to name"), - }, - Msg::UpdateFirstName(f) => match self.value.get_mut() { - Some(value) => value.first_name = f, - None => ConsoleService::info("Couldn't get mutable reference to name"), - }, - Msg::UpdateMiddleName(m) => match self.value.get_mut() { - Some(value) => value.middle_name = m, - None => ConsoleService::info("Couldn't get mutable reference to name"), - }, - Msg::UpdateLastName(l) => match self.value.get_mut() { - Some(value) => value.last_name = l, - None => ConsoleService::info("Couldn't get mutable reference to name"), - }, - Msg::UpdateSuffix(s) => match self.value.get_mut() { - Some(value) => value.suffix = s, - None => ConsoleService::info("Couldn't get mutable reference to name"), - }, + Msg::UpdatePrefix(p) => self.value.prefix = p, + Msg::UpdateFirstName(f) => self.value.first_name = f, + Msg::UpdateMiddleName(m) => self.value.middle_name = m, + Msg::UpdateLastName(l) => self.value.last_name = l, + Msg::UpdateSuffix(s) => self.value.suffix = s, Msg::Generate => { self.props.generated.emit(self.value.irc()); }, diff --git a/src/view/telephone.rs b/src/view/telephone.rs index ca58538..63fdee7 100644 --- a/src/view/telephone.rs +++ b/src/view/telephone.rs @@ -1,14 +1,28 @@ +use yew::prelude::*; use yew::services::ConsoleService; use yewtil::ptr::Irc; use yewtil::ptr::Mrc; +use yewtil::NeqAssign; use crate::view::WeakComponentLink; use crate::viewmodel::Error; -use yew::prelude::*; -use yewtil::NeqAssign; use crate::viewmodel::telephone::*; use crate::viewmodel::VCardPropertyInputObject; use super::VCardPropertyInputComponent; +/// View Component for a `telephone` field +/// +/// # Examples +/// +/// ```compile_fail +/// let html = html!{ +/// | +/// Msg::GeneratedTelephone(some_telephone) +/// ) +/// /> +/// }; +/// ``` pub struct TelephoneView { props: Props, value: Mrc, -- cgit v1.2.3