Skip to content

Commit

Permalink
Doc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jstarry committed Oct 1, 2019
1 parent f8ecf19 commit 07a7147
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 103 deletions.
15 changes: 7 additions & 8 deletions src/components/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@
//! helps you to track selected value in an original type. Example:
//!
//! ```
//!# use yew::{Html, Component, components::Select, ComponentLink, Renderable, html};
//!# struct Model;
//!# impl Component for Model {
//!# type Message = ();type Properties = ();
//!# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
//!# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
//!# }
//!# impl Renderable<Model> for Model {fn view(&self) -> Html<Model> {unimplemented!()}}
//!# use yew::{Html, Component, components::Select, ComponentLink, html};
//! #[derive(PartialEq, Clone)]
//! enum Scene {
//! First,
//! Second,
//! }
//!# struct Model;
//!# impl Component for Model {
//!# type Message = ();type Properties = ();
//!# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
//!# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
//!# fn view(&self) -> Html<Model> {unimplemented!()}}
//! impl ToString for Scene {
//! fn to_string(&self) -> String {
//! match self {
Expand Down
146 changes: 73 additions & 73 deletions src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,28 @@ pub type Html<MSG> = VNode<MSG>;
/// # Example
/// **`model.rs`**
///
/// In this example, the Wrapper component is used to wrap other elements.
/// In this example, the `Wrapper` component is used to wrap other elements.
/// ```
///
///# use yew::{Children, Html, Renderable, Properties, Component, ComponentLink, html};
/// #[derive(Properties)]
///# use yew::{Children, Html, Properties, Component, ComponentLink, html};
///# #[derive(Properties)]
///# struct WrapperProps {
///# children: Children<Wrapper>,
///# children: Children<Wrapper>,
///# }
///# struct Wrapper;
///# impl Component for Wrapper{
///# type Message = ();type Properties = WrapperProps;
///# type Message = ();
///# type Properties = WrapperProps;
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# }
///# impl Renderable<Wrapper> for Wrapper {
///# fn view(&self) -> Html<Wrapper> { // This is a recursively defined render impl - which would never work. This is done for space convenience.
/// html!{
/// <Wrapper>
/// <h4> {"Hi"} </h4>
/// <div> {"Hello"} </div>
/// </Wrapper>
///# // This is not a valid implementation. This is done for space convenience.
///# fn view(&self) -> Html<Self> {
/// html! {
/// <Wrapper>
/// <h4>{ "Hi" }</h4>
/// <div>{ "Hello" }</div>
/// </Wrapper>
/// }
///# }
///# }
///# }
/// ```
///
Expand All @@ -87,25 +86,26 @@ pub type Html<MSG> = VNode<MSG>;
/// The Wrapper component must define a `children` property in order to wrap other elements. The
/// children property can be used to render the wrapped elements.
/// ```
///# use yew::{Children, Html, Renderable, Properties, Component, ComponentLink, html};
///# struct Wrapper {props: WrapperProps};
///# impl Component for Wrapper{
///# type Message = ();type Properties = WrapperProps;
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# }
///# use yew::{Children, Html, Properties, Renderable, Component, ComponentLink, html};
/// #[derive(Properties)]
/// struct WrapperProps {
/// children: Children<Wrapper>,
/// children: Children<Wrapper>,
/// }
/// impl Renderable<Wrapper> for Wrapper {
/// fn view(&self) -> Html<Wrapper> {
/// html!{
/// <div id="container">
/// { self.props.children.view() }
/// </div>
/// }
/// }
///
///# struct Wrapper {props: WrapperProps};
/// impl Component for Wrapper {
/// // ...
///# type Message = ();
///# type Properties = WrapperProps;
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
/// fn view(&self) -> Html<Wrapper> {
/// html! {
/// <div id="container">
/// { self.props.children.render() }
/// </div>
/// }
/// }
/// }
/// ```
pub type Children<T> = ChildrenRenderer<Html<T>>;
Expand All @@ -117,33 +117,32 @@ pub type Children<T> = ChildrenRenderer<Html<T>>;
///
/// In this example, the `List` component can wrap `ListItem` components.
/// ```
/// use yew::{html, Component, Renderable, Html, ComponentLink, ChildrenWithProps, Properties};
///
///# use yew::{html, Component, Renderable, Html, ComponentLink, ChildrenWithProps, Properties};
///#
///# #[derive(Properties)]
///# struct ListProps {
///# children: ChildrenWithProps<ListItem, List>,
///# children: ChildrenWithProps<ListItem, List>,
///# }
///
///# struct List;
///# impl Component for List {
///# type Message = ();type Properties = ListProps;
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# type Message = ();
///# type Properties = ListProps;
///# fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self, msg: Self::Message) -> bool {unimplemented!()}
///# fn view(&self) -> Html<List> {unimplemented!()}
///# }
///# impl Renderable<List> for List {fn view(&self) -> Html<List> {unimplemented!()}}
///
///
///# #[derive(Properties)]
///# struct ListItemProps {
///# value: String
///# value: String
///# }
///# struct ListItem;
///# impl Component for ListItem {
///# type Message = ();type Properties = ListItemProps;
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# type Message = ();
///# type Properties = ListItemProps;
///# fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self, msg: Self::Message) -> bool {unimplemented!()}
///# fn view(&self) -> Html<Self> {unimplemented!()}
///# }
///# impl Renderable<ListItem> for ListItem {fn view(&self) -> Html<ListItem> {unimplemented!()}}
///# fn view() -> Html<List> {
/// html!{
/// <List>
Expand All @@ -160,42 +159,43 @@ pub type Children<T> = ChildrenRenderer<Html<T>>;
/// The `List` component must define a `children` property in order to wrap the list items. The
/// `children` property can be used to filter, mutate, and render the items.
/// ```
/// use yew::ChildrenWithProps;
///# use yew::{html, Component, Renderable, Html, ComponentLink, Properties};
///# use yew::{html, Component, Html, ChildrenWithProps, ComponentLink, Properties};
///#
/// #[derive(Properties)]
/// struct ListProps {
/// children: ChildrenWithProps<ListItem, List>,
/// }
///
///# struct List {props: ListProps};
///# impl Component for List {
///# type Message = ();type Properties = ListProps;
/// impl Component for List {
///# type Message = ();
///# type Properties = ListProps;
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# }
///
/// // ...
/// fn view(&self) -> Html<Self> {
/// html!{{
/// for self.props.children.iter().map(|mut item| {
/// item.props.value = format!("item-{}", item.props.value);
/// item
/// })
/// }}
/// }
/// }
///#
///# #[derive(Properties)]
///# struct ListItemProps {
///# value: String
///# value: String
///# }
///#
///# struct ListItem;
///# impl Component for ListItem {
///# type Message = ();type Properties = ListItemProps;
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# type Message = ();
///# type Properties = ListItemProps;
///# fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self, msg: Self::Message) -> bool {unimplemented!()}
///# fn view(&self) -> Html<ListItem> {unimplemented!()}
///# }
///# impl Renderable<ListItem> for ListItem {fn view(&self) -> Html<ListItem> {unimplemented!()}}
///
/// #[derive(Properties)]
/// struct ListProps {
/// children: ChildrenWithProps<ListItem, List>,
/// }
///
/// impl Renderable<List> for List {
/// fn view(&self) -> Html<List> {
/// html!{{
/// for self.props.children.iter().map(|mut item| {
/// item.props.value = format!("item-{}", item.props.value);
/// item
/// })
/// }}
/// }
/// }
/// ```
pub type ChildrenWithProps<C, P> = ChildrenRenderer<VChild<C, P>>;

Expand Down
41 changes: 19 additions & 22 deletions src/services/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ impl FetchService {
///# type Message = Msg;type Properties = ();
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# fn view(&self) -> Html<Comp> {unimplemented!()}
///# }
///# impl Renderable<Comp> for Comp {fn view(&self) -> Html<Comp> {unimplemented!()}}
///# enum Msg {
///# Noop,
///# Error
Expand All @@ -151,15 +151,15 @@ impl FetchService {
///# let mut link: ComponentLink<Comp> = unimplemented!();
///# let mut fetch_service: FetchService = FetchService::new();
///# let post_request: Request<Result<String, failure::Error>> = unimplemented!();
/// let task = fetch_service.fetch(
/// post_request,
/// link.send_back(|response: Response<Result<String, failure::Error>>| {
/// let task = fetch_service.fetch(
/// post_request,
/// link.send_back(|response: Response<Result<String, failure::Error>>| {
/// if response.status().is_success() {
/// Msg::Noop
/// } else {
/// Msg::Error
/// }
/// })
/// }),
/// );
///# }
/// ```
Expand All @@ -180,8 +180,8 @@ impl FetchService {
///# type Message = Msg;type Properties = ();
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# fn view(&self) -> Html<Comp> {unimplemented!()}
///# }
///# impl Renderable<Comp> for Comp {fn view(&self) -> Html<Comp> {unimplemented!()}}
///# enum Msg {
///# FetchResourceComplete(Data),
///# FetchResourceFailed
Expand All @@ -190,23 +190,20 @@ impl FetchService {
/// struct Data {
/// value: String
/// }
///
///# fn dont_execute() {
///# let mut link: ComponentLink<Comp> = unimplemented!();
/// let get_request = Request::get("/thing").body(Nothing).unwrap();
/// let callback = link.send_back(|response: Response<Json<Result<Data, failure::Error>>>| {
/// if let (meta, Json(Ok(body))) = response.into_parts() {
/// if meta.status.is_success() {
/// return Msg::FetchResourceComplete(body);
/// }
/// if let (meta, Json(Ok(body))) = response.into_parts() {
/// if meta.status.is_success() {
/// return Msg::FetchResourceComplete(body);
/// }
/// Msg::FetchResourceFailed
/// }
/// );
/// Msg::FetchResourceFailed
/// });
///
/// let task = FetchService::new().fetch(
/// get_request,
/// callback
/// );
/// let task = FetchService::new().fetch(get_request, callback);
///# }
/// ```
///
Expand All @@ -232,11 +229,12 @@ impl FetchService {
///# use http::Response;
///# struct Comp;
///# impl Component for Comp {
///# type Message = Msg;type Properties = ();
///# fn create(props: Self::Properties,link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self,msg: Self::Message) -> bool {unimplemented!()}
///# type Message = Msg;
///# type Properties = ();
///# fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {unimplemented!()}
///# fn update(&mut self, msg: Self::Message) -> bool {unimplemented!()}
///# fn view(&self) -> Html<Comp> {unimplemented!()}
///# }
///# impl Renderable<Comp> for Comp {fn view(&self) -> Html<Comp> {unimplemented!()}}
///# pub enum Msg {}
///# fn dont_execute() {
///# let mut link: ComponentLink<Comp> = unimplemented!();
Expand All @@ -248,8 +246,7 @@ impl FetchService {
/// credentials: Some(Credentials::SameOrigin),
/// ..FetchOptions::default()
/// };
///# let mut fetch_service = FetchService::new();
/// let task = fetch_service.fetch_with_options(request, options, callback);
/// let task = FetchService::new().fetch_with_options(request, options, callback);
///# }
/// ```
pub fn fetch_with_options<IN, OUT: 'static>(
Expand Down

0 comments on commit 07a7147

Please sign in to comment.