Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up exported apis and doc visibility #977

Merged
merged 4 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ cloned is when a wrapper component re-renders nested children components.
```rust
use stdweb::web::html_element::InputElement;
use stdweb::web::IHtmlElement;
use yew::*;
use yew::prelude::*;

pub struct Input {
node_ref: NodeRef,
Expand Down
2 changes: 1 addition & 1 deletion crates/macro/src/html_tree/html_component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl ToTokens for HtmlComponent {
Props::List(list_props) => {
let set_props = list_props.props.iter().map(|HtmlProp { label, value }| {
quote_spanned! { value.span()=> .#label(
<::yew::virtual_dom::vcomp::VComp as ::yew::virtual_dom::Transformer<_, _>>::transform(
<::yew::virtual_dom::VComp as ::yew::virtual_dom::Transformer<_, _>>::transform(
#value
)
)}
Expand Down
2 changes: 1 addition & 1 deletion crates/macro/src/html_tree/html_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl ToTokens for HtmlList {
let children = &self.0;
tokens.extend(quote! {
::yew::virtual_dom::VNode::VList(
::yew::virtual_dom::vlist::VList::new_with_children({
::yew::virtual_dom::VList::new_with_children({
let mut v = ::std::vec::Vec::new();
#(v.extend(::yew::utils::NodeSeq::from(#children));)*
v
Expand Down
4 changes: 2 additions & 2 deletions crates/macro/src/html_tree/html_tag/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ impl ToTokens for HtmlTag {

quote_spanned! {name.span()=> {
::yew::html::#name::Wrapper::new(
<::yew::virtual_dom::vtag::VTag as ::yew::virtual_dom::Transformer<_, _>>::transform(
<::yew::virtual_dom::VTag as ::yew::virtual_dom::Transformer<_, _>>::transform(
#callback
)
)
}}
});

tokens.extend(quote! {{
let mut #vtag = ::yew::virtual_dom::vtag::VTag::new(#name);
let mut #vtag = ::yew::virtual_dom::VTag::new(#name);
#(#set_kind)*
#(#set_value)*
#(#add_href)*
Expand Down
4 changes: 2 additions & 2 deletions examples/pub_sub/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#![recursion_limit = "128"]

mod event_bus;
mod subscriber;
mod producer;
mod subscriber;

use subscriber::Subsciber;
use producer::Producer;
use subscriber::Subsciber;
use yew::{html, Component, ComponentLink, Html, ShouldRender};

pub struct Model {}
Expand Down
44 changes: 16 additions & 28 deletions examples/std_web/two_apps/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#![recursion_limit = "256"]

use yew::html::Scope;
/// This example demonstrates low-level usage of scopes.
use yew::{html, Component, ComponentLink, Html, ShouldRender};

pub struct Model {
link: ComponentLink<Self>,
scope: Option<Scope<Model>>,
opposite: Option<ComponentLink<Model>>,
selector: &'static str,
title: String,
}

pub enum Msg {
SetScope(Scope<Model>),
SetOpposite(ComponentLink<Model>),
SendToOpposite(String),
SetTitle(String),
}
Expand All @@ -24,45 +22,35 @@ impl Component for Model {
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
Model {
link,
scope: None,
opposite: None,
selector: "",
title: "Nothing".into(),
}
}

fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg {
Msg::SetScope(scope) => {
self.scope = Some(scope);
Msg::SetOpposite(opposite) => {
self.opposite = Some(opposite);
}
Msg::SendToOpposite(title) => {
self.scope
self.opposite
.as_mut()
.unwrap()
.send_message(Msg::SetTitle(title));
}
Msg::SetTitle(title) => {
match title.as_ref() {
"Ping" => {
self.scope
.as_mut()
.unwrap()
.send_message(Msg::SetTitle("Pong".into()));
}
"Pong" => {
self.scope
.as_mut()
.unwrap()
.send_message(Msg::SetTitle("Pong Done".into()));
}
"Pong Done" => {
self.scope
.as_mut()
.unwrap()
.send_message(Msg::SetTitle("Ping Done".into()));
}
_ => {}
let send_msg = match title.as_ref() {
"Ping" => Some(Msg::SetTitle("Pong".into())),
"Pong" => Some(Msg::SetTitle("Pong Done".into())),
"Pong Done" => Some(Msg::SetTitle("Ping Done".into())),
_ => None,
};

if let Some(send_msg) = send_msg {
self.opposite.as_mut().unwrap().send_message(send_msg);
}

self.title = title;
}
}
Expand Down
44 changes: 16 additions & 28 deletions examples/web_sys/two_apps/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
#![recursion_limit = "256"]

use yew::html::Scope;
/// This example demonstrates low-level usage of scopes.
use yew::{html, Component, ComponentLink, Html, ShouldRender};

pub struct Model {
link: ComponentLink<Self>,
scope: Option<Scope<Model>>,
opposite: Option<ComponentLink<Model>>,
selector: &'static str,
title: String,
}

pub enum Msg {
SetScope(Scope<Model>),
SetOpposite(ComponentLink<Model>),
SendToOpposite(String),
SetTitle(String),
}
Expand All @@ -24,45 +22,35 @@ impl Component for Model {
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
Model {
link,
scope: None,
opposite: None,
selector: "",
title: "Nothing".into(),
}
}

fn update(&mut self, msg: Self::Message) -> ShouldRender {
match msg {
Msg::SetScope(scope) => {
self.scope = Some(scope);
Msg::SetOpposite(opposite) => {
self.opposite = Some(opposite);
}
Msg::SendToOpposite(title) => {
self.scope
self.opposite
.as_mut()
.unwrap()
.send_message(Msg::SetTitle(title));
}
Msg::SetTitle(title) => {
match title.as_ref() {
"Ping" => {
self.scope
.as_mut()
.unwrap()
.send_message(Msg::SetTitle("Pong".into()));
}
"Pong" => {
self.scope
.as_mut()
.unwrap()
.send_message(Msg::SetTitle("Pong Done".into()));
}
"Pong Done" => {
self.scope
.as_mut()
.unwrap()
.send_message(Msg::SetTitle("Ping Done".into()));
}
_ => {}
let send_msg = match title.as_ref() {
"Ping" => Some(Msg::SetTitle("Pong".into())),
"Pong" => Some(Msg::SetTitle("Pong Done".into())),
"Pong Done" => Some(Msg::SetTitle("Ping Done".into())),
_ => None,
};

if let Some(send_msg) = send_msg {
self.opposite.as_mut().unwrap().send_message(send_msg);
}

self.title = title;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cfg_if! {

/// Serializable messages to worker
#[derive(Serialize, Deserialize, Debug)]
pub enum ToWorker<T> {
enum ToWorker<T> {
/// Client is connected
Connected(HandlerId),
/// Incoming message to Worker
Expand All @@ -44,7 +44,7 @@ pub enum ToWorker<T> {

/// Serializable messages sent by worker to consumer
#[derive(Serialize, Deserialize, Debug)]
pub enum FromWorker<T> {
enum FromWorker<T> {
/// Worker sends this message when `wasm` bundle has loaded.
WorkerLoaded,
/// Outgoing message to consumer
Expand Down
18 changes: 11 additions & 7 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module contains the `App` struct, which is used to bootstrap
//! a component in an isolated scope.

use crate::html::{Component, NodeRef, Scope};
use crate::html::{Component, ComponentLink, NodeRef, Scope};
use crate::utils::document;
use cfg_if::cfg_if;
cfg_if! {
Expand Down Expand Up @@ -38,7 +38,7 @@ where
/// which will update the state of the model and a `view` function which
/// will render the model to a virtual DOM tree. If you would like to pass props,
/// use the `mount_with_props` method.
pub fn mount(self, element: Element) -> Scope<COMP> {
pub fn mount(self, element: Element) -> ComponentLink<COMP> {
clear_element(&element);
self.scope.mount_in_place(
element,
Expand All @@ -49,7 +49,7 @@ where
}

/// Alias to `mount("body", ...)`.
pub fn mount_to_body(self) -> Scope<COMP> {
pub fn mount_to_body(self) -> ComponentLink<COMP> {
// Bootstrap the component for `Window` environment only (not for `Worker`)
let element = document()
.query_selector("body")
Expand All @@ -62,7 +62,7 @@ where
/// element at the root of the HTML generated by its `view` method. Use this method when you
/// need to manipulate the body element. For example, adding/removing app-wide
/// CSS classes of the body element.
pub fn mount_as_body(self) -> Scope<COMP> {
pub fn mount_as_body(self) -> ComponentLink<COMP> {
let html_element = document()
.query_selector("html")
.expect("can't get html node for rendering")
Expand Down Expand Up @@ -97,14 +97,18 @@ where
/// similarly to the `program` function in Elm. You should provide an initial model, `update`
/// function which will update the state of the model and a `view` function which
/// will render the model to a virtual DOM tree.
pub fn mount_with_props(self, element: Element, props: COMP::Properties) -> Scope<COMP> {
pub fn mount_with_props(
self,
element: Element,
props: COMP::Properties,
) -> ComponentLink<COMP> {
clear_element(&element);
self.scope
.mount_in_place(element, None, NodeRef::default(), props)
}

/// Alias to `mount_with_props("body", ...)`.
pub fn mount_to_body_with_props(self, props: COMP::Properties) -> Scope<COMP> {
pub fn mount_to_body_with_props(self, props: COMP::Properties) -> ComponentLink<COMP> {
// Bootstrap the component for `Window` environment only (not for `Worker`)
let element = document()
.query_selector("body")
Expand All @@ -117,7 +121,7 @@ where
/// has a body element at the root of the HTML generated by its `view` method. Use this method
/// when you need to manipulate the body element. For example, adding/removing app-wide
/// CSS classes of the body element.
pub fn mount_as_body_with_props(self, props: COMP::Properties) -> Scope<COMP> {
pub fn mount_as_body_with_props(self, props: COMP::Properties) -> ComponentLink<COMP> {
let html_element = document()
.query_selector("html")
.expect("can't get html node for rendering")
Expand Down
2 changes: 2 additions & 0 deletions src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! This module contains useful components.
//! At this moment it includes typed `Select` only.

#[doc(hidden)]
pub mod select;

#[doc(inline)]
pub use self::select::Select;
28 changes: 27 additions & 1 deletion src/format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,58 @@ use anyhow::Error;
use thiserror::Error as ThisError;

#[macro_use]
pub mod macros;
mod macros;

#[cfg(feature = "bincode")]
#[doc(hidden)]
pub mod bincode;

#[cfg(feature = "cbor")]
#[doc(hidden)]
pub mod cbor;

#[doc(hidden)]
pub mod json;

#[doc(hidden)]
#[cfg(feature = "msgpack")]
pub mod msgpack;

#[doc(hidden)]
pub mod nothing;

#[cfg(feature = "toml")]
#[doc(hidden)]
pub mod toml;

#[cfg(feature = "yaml")]
#[doc(hidden)]
pub mod yaml;

#[cfg(feature = "bincode")]
#[doc(inline)]
pub use self::bincode::Bincode;

#[cfg(feature = "cbor")]
#[doc(inline)]
pub use self::cbor::Cbor;

#[doc(inline)]
pub use self::json::Json;

#[cfg(feature = "msgpack")]
#[doc(inline)]
pub use self::msgpack::MsgPack;

#[doc(inline)]
pub use self::nothing::Nothing;

#[cfg(feature = "toml")]
#[doc(inline)]
pub use self::toml::Toml;

#[cfg(feature = "yaml")]
#[doc(inline)]
pub use self::yaml::Yaml;

/// A representation of a value which can be stored and restored as a text.
Expand Down
1 change: 1 addition & 0 deletions src/html/listener/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ macro_rules! impl_action {
)*};
($($action:ident(name: $name:literal, event: $type:ident) -> $ret:ty => $convert:expr)*) => {$(
/// An abstract implementation of a listener.
#[doc(hidden)]
pub mod $action {
use cfg_if::cfg_if;
use cfg_match::cfg_match;
Expand Down
Loading