Add render method to Component and auto implement Renderable (#563)

* Add render method to Component and auto implement Renderable

* More cleanup

* Rename Renderable method from view to render

* Doc fixes

* fix

* Update CHANGELOG.md
This commit is contained in:
Justin Starry 2019-09-30 22:23:25 -04:00 committed by GitHub
parent 70a95f87bf
commit 43e9347269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 291 additions and 367 deletions

View File

@ -56,7 +56,7 @@ Yew implements strict application state management based on message passing and
`src/main.rs`
```rust
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
struct Model { }
@ -82,9 +82,7 @@ impl Component for Model {
}
}
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
// Render your model here
@ -322,7 +320,7 @@ extern crate chrono;
use chrono::prelude::*;
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
fn render(&self) -> Html<Self> {
html! {
<p>{ Local::now() }</p>
}

View File

@ -28,9 +28,7 @@
//! # fn update(&mut self, msg: Self::Message) -> ShouldRender {
//! # unimplemented!()
//! # }
//! # }
//! #
//! # impl Renderable<Component> for Component {
//! # fn view(&self) -> Html<Self> {
//! #
//! // ...

View File

@ -2,7 +2,7 @@
use stdweb::web::Date;
use yew::services::ConsoleService;
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
console: ConsoleService,
@ -45,9 +45,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -143,15 +143,13 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
match self.scene {
Scene::ClientsList => html! {
<div class="crm">
<div class="clients">
{ for self.database.clients.iter().map(Renderable::view) }
{ for self.database.clients.iter().map(Renderable::render) }
</div>
<button onclick=|_| Msg::SwitchTo(Scene::NewClientForm(Client::empty()))>{ "Add New" }</button>
<button onclick=|_| Msg::SwitchTo(Scene::Settings)>{ "Settings" }</button>
@ -180,7 +178,7 @@ impl Renderable<Model> for Model {
}
impl Renderable<Model> for Client {
fn view(&self) -> Html<Model> {
fn render(&self) -> Html<Model> {
html! {
<div class="client">
<p>{ format!("First Name: {}", self.first_name) }</p>

View File

@ -48,9 +48,7 @@ impl Component for Barrier {
self.onsignal = props.onsignal;
true
}
}
impl Renderable<Barrier> for Barrier {
fn view(&self) -> Html<Self> {
html! {
<div class="barrier">

View File

@ -41,9 +41,7 @@ impl Component for Button {
self.onsignal = props.onsignal;
true
}
}
impl Renderable<Button> for Button {
fn view(&self) -> Html<Self> {
html! {
<button onclick=|_| Msg::Clicked>{ &self.title }</button>

View File

@ -58,9 +58,7 @@ impl Component for Counter {
self.onclick = props.onclick;
true
}
}
impl Renderable<Counter> for Counter {
fn view(&self) -> Html<Self> {
let colorize = {
match self.color {

View File

@ -43,9 +43,7 @@ impl Component for Model {
Msg::ChildClicked(_value) => false,
}
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
let counter = |x| {
html! {

View File

@ -6,7 +6,7 @@ use yew::format::{Json, Nothing, Toml};
use yew::services::fetch::{FetchService, FetchTask, Request, Response};
use yew::services::websocket::{WebSocketService, WebSocketStatus, WebSocketTask};
use yew::services::Task;
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
type AsBinary = bool;
@ -167,9 +167,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -1,7 +1,7 @@
#![recursion_limit = "256"]
use yew::services::reader::{File, FileChunk, FileData, ReaderService, ReaderTask};
use yew::{html, ChangeData, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, ChangeData, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
link: ComponentLink<Model>,
@ -64,9 +64,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
let flag = self.by_chunks;
html! {

View File

@ -1,6 +1,6 @@
#![recursion_limit = "128"]
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
counter: usize,
@ -32,9 +32,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<>

View File

@ -4,7 +4,7 @@ use log::info;
use rand::Rng;
use std::time::Duration;
use yew::services::{IntervalService, Task};
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
#[derive(Clone, Copy, PartialEq)]
enum LifeState {
@ -205,9 +205,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -5,7 +5,15 @@ extern crate stdweb;
use stdweb::unstable::TryFrom;
use stdweb::web::Node;
use yew::virtual_dom::VNode;
use yew::{Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{Component, ComponentLink, Html, ShouldRender};
const SVG: &str = r#"
<h2>Inline SVG or <i>any</i> HTML:</h2>
<svg height="250" width="500">
<polygon points="220,10 300,210 170,250 123,234" style="fill:lime;stroke:purple;stroke-width:1" />
Sorry, your browser does not support inline SVG.
</svg>
"#;
pub struct Model {
pub value: i64,
@ -24,17 +32,7 @@ impl Component for Model {
fn update(&mut self, _: Self::Message) -> ShouldRender {
true
}
}
const SVG: &str = r#"
<h2>Inline SVG or <i>any</i> HTML:</h2>
<svg height="250" width="500">
<polygon points="220,10 300,210 170,250 123,234" style="fill:lime;stroke:purple;stroke-width:1" />
Sorry, your browser does not support inline SVG.
</svg>
"#;
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
let js_svg = js! {
var div = document.createElement("div");

View File

@ -52,9 +52,7 @@ impl Component for Model {
fn change(&mut self, _: Self::Properties) -> ShouldRender {
false
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -1,7 +1,7 @@
//! This demo originally created by https://github.com/qthree
//! Source: https://github.com/qthree/yew_table100x100_test
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
selected: Option<(u32, u32)>,
@ -28,6 +28,14 @@ impl Component for Model {
}
true
}
fn view(&self) -> Html<Self> {
html! {
<table>
{ (0..99).map(|row| view_row(self.selected, row)).collect::<Html<Self>>() }
</table>
}
}
}
fn square_class(this: (u32, u32), selected: Option<(u32, u32)>) -> &'static str {
@ -54,13 +62,3 @@ fn view_row(selected: Option<(u32, u32)>, row: u32) -> Html<Model> {
</tr>
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<table>
{ (0..99).map(|row| view_row(self.selected, row)).collect::<Html<Self>>() }
</table>
}
}
}

View File

@ -1,4 +1,4 @@
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
pub struct Model {}
@ -20,9 +20,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -1,4 +1,4 @@
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
name: String,
@ -26,9 +26,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -6,7 +6,7 @@ pub mod native_worker;
use log::info;
use yew::worker::*;
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
worker: Box<Bridge<native_worker::Worker>>,
@ -65,9 +65,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -33,9 +33,7 @@ impl Component for ListHeader {
}
false
}
}
impl Renderable<ListHeader> for ListHeader {
fn view(&self) -> Html<Self> {
html! {
<div class="list-header" onmouseover=|_| Msg::Hover>

View File

@ -38,9 +38,7 @@ impl Component for ListItem {
}
false
}
}
impl Renderable<ListItem> for ListItem {
fn view(&self) -> Html<Self> {
html! {
<div class="list-item" onmouseover=|_| Msg::Hover>
@ -59,7 +57,7 @@ impl ListItem {
html! {
<div class="list-item-details">
{ self.props.children.view() }
{ self.props.children.render() }
</div>
}
}

View File

@ -22,9 +22,7 @@ impl Component for Model {
fn update(&mut self, _: Self::Message) -> ShouldRender {
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div class="main">

View File

@ -68,9 +68,7 @@ impl Component for List {
}
true
}
}
impl Renderable<List> for List {
fn view(&self) -> Html<Self> {
html! {
<div
@ -143,7 +141,7 @@ impl fmt::Display for Hovered {
impl<CHILD> From<VChild<CHILD, List>> for ListVariant
where
CHILD: Component + Renderable<CHILD>,
CHILD: Component,
CHILD::Properties: Into<Variants>,
{
fn from(vchild: VChild<CHILD, List>) -> Self {

View File

@ -9,7 +9,7 @@ pub mod gravatar;
use failure::Error;
use yew::services::fetch::FetchTask;
use yew::{html, Callback, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Callback, Component, ComponentLink, Html, ShouldRender};
use ccxt::CcxtService;
use gravatar::{GravatarService, Profile};
@ -64,9 +64,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
let view_exchange = |exchange| {
html! {

View File

@ -1,7 +1,7 @@
use crate::router::{Request, Route, Router};
use log::info;
use yew::agent::Bridged;
use yew::{html, Bridge, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Bridge, Component, ComponentLink, Html, ShouldRender};
pub struct BModel {
number: Option<usize>,
@ -105,8 +105,7 @@ impl Component for BModel {
// Apparently change MUST be implemented in this case, even though no props were changed
true
}
}
impl Renderable<BModel> for BModel {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -67,9 +67,7 @@ impl Component for Model {
}
}
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>
@ -78,7 +76,7 @@ impl Renderable<Model> for Model {
<RouterButton text="Go to B" path="/b" />
</nav>
<div>
{self.child.view()}
{self.child.render()}
</div>
</div>
}
@ -86,7 +84,7 @@ impl Renderable<Model> for Model {
}
impl Renderable<Model> for Child {
fn view(&self) -> Html<Model> {
fn render(&self) -> Html<Model> {
match self {
Child::A => html! {
<>

View File

@ -60,13 +60,12 @@ impl Component for RouterButton {
}
}
}
fn change(&mut self, props: Self::Properties) -> ShouldRender {
self.props = props;
true
}
}
impl Renderable<RouterButton> for RouterButton {
fn view(&self) -> Html<RouterButton> {
html! {
<button

View File

@ -19,7 +19,7 @@ use timer::Model as Timer;
use todomvc::Model as Todomvc;
use two_apps::Model as TwoApps;
use yew::components::Select;
use yew::{html, App, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, App, Component, ComponentLink, Html, ShouldRender};
#[derive(Clone, Debug, Display, EnumString, EnumIter, PartialEq)]
enum Scene {
@ -64,9 +64,7 @@ impl Component for Model {
}
}
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div id="fullscreen">

View File

@ -1,6 +1,6 @@
#![recursion_limit = "128"]
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
value: String,
@ -30,9 +30,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -2,7 +2,7 @@
use std::time::Duration;
use yew::services::{ConsoleService, IntervalService, Task, TimeoutService};
use yew::{html, Callback, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Callback, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
timeout: TimeoutService,
@ -96,9 +96,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
let view_message = |message| {
html! { <p>{ message }</p> }

View File

@ -6,7 +6,7 @@ use strum_macros::{EnumIter, ToString};
use yew::events::IKeyboardEvent;
use yew::format::Json;
use yew::services::storage::{Area, StorageService};
use yew::{html, Component, ComponentLink, Href, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Href, Html, ShouldRender};
const KEY: &'static str = "yew.todomvc.self";
@ -115,9 +115,7 @@ impl Component for Model {
self.storage.store(KEY, Json(&self.state.entries));
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div class="todomvc-wrapper">

View File

@ -2,7 +2,7 @@
use yew::html::Scope;
/// This example demonstrates low-level usage of scopes.
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
pub struct Model {
scope: Option<Scope<Model>>,
@ -66,9 +66,7 @@ impl Component for Model {
}
true
}
}
impl Renderable<Model> for Model {
fn view(&self) -> Html<Self> {
html! {
<div>

View File

@ -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, Renderable, Scope};
use crate::html::{Component, Scope};
use stdweb::web::{document, Element, INode, IParentNode};
/// An application instance.
@ -12,7 +12,7 @@ pub struct App<COMP: Component> {
impl<COMP> Default for App<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
fn default() -> Self {
App::new()
@ -21,7 +21,7 @@ where
impl<COMP> App<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
COMP::Properties: Default,
{
/// The main entrypoint of a yew program. It works similarly to the `program`
@ -68,7 +68,7 @@ where
impl<COMP> App<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
/// Creates a new `App` with a component in a context.
pub fn new() -> Self {

View File

@ -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 {
@ -34,7 +33,7 @@
//! ```
use crate::callback::Callback;
use crate::html::{ChangeData, Component, ComponentLink, Html, Renderable, ShouldRender};
use crate::html::{ChangeData, Component, ComponentLink, Html, ShouldRender};
use crate::macros::{html, Properties};
/// `Select` component.
@ -64,7 +63,7 @@ pub struct Props<T> {
impl<T> Component for Select<T>
where
T: PartialEq + Clone + 'static,
T: ToString + PartialEq + Clone + 'static,
{
type Message = Msg;
type Properties = Props<T>;
@ -91,12 +90,7 @@ where
self.props = props;
true
}
}
impl<T> Renderable<Select<T>> for Select<T>
where
T: ToString + PartialEq + Clone + 'static,
{
fn view(&self) -> Html<Self> {
let selected = self.props.selected.as_ref();
let view_option = |value: &T| {

View File

@ -35,7 +35,7 @@ macro_rules! impl_action {
impl<T, COMP> Listener<COMP> for Wrapper<T>
where
T: Fn($ret) -> COMP::Message + 'static,
COMP: Component + Renderable<COMP>,
COMP: Component,
{
fn kind(&self) -> &'static str {
stringify!($action)

View File

@ -42,6 +42,8 @@ pub trait Component: Sized + 'static {
fn change(&mut self, _: Self::Properties) -> ShouldRender {
true
}
/// Called by rendering loop.
fn view(&self) -> Html<Self>;
/// Called for finalization on the final point of the component's lifetime.
fn destroy(&mut self) {} // TODO Replace with `Drop`
}
@ -54,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>
/// }
///# }
///# }
///# }
/// ```
///
@ -85,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>>;
@ -115,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>
@ -158,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};
///# struct List {props: 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!()}
///# }
///
///# #[derive(Properties)]
///# struct ListItemProps {
///# 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!()}
///# }
///# impl Renderable<ListItem> for ListItem {fn view(&self) -> Html<ListItem> {unimplemented!()}}
///
///# use yew::{html, Component, Html, ChildrenWithProps, ComponentLink, Properties};
///#
/// #[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
/// })
/// }}
/// }
///# struct List {props: 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
///# }
///#
///# 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!()}
///# fn view(&self) -> Html<ListItem> {unimplemented!()}
///# }
/// ```
pub type ChildrenWithProps<C, P> = ChildrenRenderer<VChild<C, P>>;
@ -249,7 +251,7 @@ impl<T, COMP: Component> Renderable<COMP> for ChildrenRenderer<T>
where
T: Into<VNode<COMP>>,
{
fn view(&self) -> Html<COMP> {
fn render(&self) -> Html<COMP> {
VList {
childs: self.iter().map(|c| c.into()).collect(),
}
@ -260,7 +262,13 @@ where
/// Should be rendered relative to context and component environment.
pub trait Renderable<COMP: Component> {
/// Called by rendering loop.
fn view(&self) -> Html<COMP>;
fn render(&self) -> Html<COMP>;
}
impl<COMP: Component> Renderable<COMP> for COMP {
fn render(&self) -> Html<COMP> {
self.view()
}
}
/// Trait for building properties for a component
@ -295,7 +303,7 @@ pub struct ComponentLink<COMP: Component> {
impl<COMP> ComponentLink<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
/// Create link for a scope.
fn connect(scope: &Scope<COMP>) -> Self {

View File

@ -35,7 +35,7 @@ impl<COMP: Component> Clone for Scope<COMP> {
impl<COMP> Scope<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
pub(crate) fn create(&mut self) {
let shared_state = self.shared_state.clone();
@ -118,7 +118,7 @@ struct CreatedState<COMP: Component> {
occupied: Option<NodeCell>,
}
impl<COMP: Component + Renderable<COMP>> CreatedState<COMP> {
impl<COMP: Component> CreatedState<COMP> {
/// Called once immediately after the component is created.
fn mounted(mut self) -> Self {
if self.component.mounted() {
@ -129,7 +129,7 @@ impl<COMP: Component + Renderable<COMP>> CreatedState<COMP> {
}
fn update(mut self) -> Self {
let mut next_frame = self.component.view();
let mut next_frame = self.component.render();
let node = next_frame.apply(&self.element, None, self.last_frame, &self.env);
if let Some(ref mut cell) = self.occupied {
*cell.borrow_mut() = node;
@ -142,7 +142,7 @@ impl<COMP: Component + Renderable<COMP>> CreatedState<COMP> {
impl<COMP> Scope<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
/// visible for testing
pub fn new() -> Self {
@ -177,7 +177,7 @@ where
impl<COMP> Default for Scope<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
fn default() -> Self {
Scope::new()
@ -193,7 +193,7 @@ where
impl<COMP> Runnable for CreateComponent<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
fn run(self: Box<Self>) {
let current_state = self.shared_state.replace(ComponentState::Processing);
@ -218,7 +218,7 @@ where
impl<COMP> Runnable for DestroyComponent<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
fn run(self: Box<Self>) {
match self.shared_state.replace(ComponentState::Destroyed) {
@ -249,7 +249,7 @@ where
impl<COMP> Runnable for UpdateComponent<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
fn run(self: Box<Self>) {
let current_state = self.shared_state.replace(ComponentState::Processing);

View File

@ -33,9 +33,7 @@
//! }
//! true
//! }
//! }
//!
//! impl Renderable<Model> for Model {
//! fn view(&self) -> Html<Self> {
//! html! {
//! <div>
@ -116,7 +114,7 @@ pub fn run_loop() {
/// Starts an app mounted to a body of the document.
pub fn start_app<COMP>()
where
COMP: Component + Renderable<COMP>,
COMP: Component,
COMP::Properties: Default,
{
initialize();
@ -127,7 +125,7 @@ where
/// Starts an app mounted to a body of the document.
pub fn start_app_with_props<COMP>(props: COMP::Properties)
where
COMP: Component + Renderable<COMP>,
COMP: Component,
{
initialize();
App::<COMP>::new().mount_to_body_with_props(props);

View File

@ -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
@ -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
/// }
/// })
/// }),
/// );
///# }
/// ```
@ -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
@ -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);
///# }
/// ```
///
@ -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!();
@ -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>(

View File

@ -2,7 +2,7 @@
use super::{VDiff, VNode};
use crate::callback::Callback;
use crate::html::{Component, ComponentUpdate, NodeCell, Renderable, Scope};
use crate::html::{Component, ComponentUpdate, NodeCell, Scope};
use std::any::TypeId;
use std::cell::RefCell;
use std::rc::Rc;
@ -53,7 +53,7 @@ where
impl<COMP, CHILD> From<VChild<CHILD, COMP>> for VComp<COMP>
where
COMP: Component,
CHILD: Component + Renderable<CHILD>,
CHILD: Component,
{
fn from(vchild: VChild<CHILD, COMP>) -> Self {
VComp::new::<CHILD>(vchild.props, vchild.scope)
@ -82,7 +82,7 @@ impl<COMP: Component> VComp<COMP> {
/// This method prepares a generator to make a new instance of the `Component`.
pub fn new<CHILD>(props: CHILD::Properties, scope_holder: ScopeHolder<COMP>) -> Self
where
CHILD: Component + Renderable<CHILD>,
CHILD: Component,
{
let generator = move |generator_type: GeneratorType, parent: Scope<COMP>| -> Mounted {
*scope_holder.borrow_mut() = Some(parent);
@ -171,7 +171,7 @@ where
impl<'a, COMP, F, IN> Transformer<COMP, F, Callback<IN>> for VComp<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
F: Fn(IN) -> COMP::Message + 'static,
{
fn transform(scope: ScopeHolder<COMP>, from: F) -> Callback<IN> {
@ -189,7 +189,7 @@ where
impl<'a, COMP, F, IN> Transformer<COMP, F, Option<Callback<IN>>> for VComp<COMP>
where
COMP: Component + Renderable<COMP>,
COMP: Component,
F: Fn(IN) -> COMP::Message + 'static,
{
fn transform(scope: ScopeHolder<COMP>, from: F) -> Option<Callback<IN>> {

View File

@ -105,7 +105,7 @@ impl<COMP: Component> From<VComp<COMP>> for VNode<COMP> {
impl<COMP, CHILD> From<VChild<CHILD, COMP>> for VNode<COMP>
where
COMP: Component,
CHILD: Component + Renderable<CHILD>,
CHILD: Component,
{
fn from(vchild: VChild<CHILD, COMP>) -> Self {
VNode::VComp(VComp::from(vchild))
@ -120,7 +120,7 @@ impl<COMP: Component, T: ToString> From<T> for VNode<COMP> {
impl<'a, COMP: Component> From<&'a dyn Renderable<COMP>> for VNode<COMP> {
fn from(value: &'a dyn Renderable<COMP>) -> Self {
value.view()
value.render()
}
}

View File

@ -2,7 +2,7 @@
macro_rules! pass_helper {
( @html ) => { html! {} };
( @html html! { $($view:tt)* }; $($tail:tt)* ) => {
let _: Html<Self> = html! { $($view)* };
let _: Html<TestComponent> = html! { $($view)* };
pass_helper! { @ html $($tail)* }
};
( @html $head:stmt; $($tail:tt)* ) => {
@ -13,8 +13,9 @@ macro_rules! pass_helper {
mod test_component;
use test_component::TestComponent;
use yew::prelude::*;
impl Renderable<TestComponent> for TestComponent {
fn view(&self) -> Html<Self> {
struct SubComponent;
impl Renderable<TestComponent> for SubComponent {
fn render(&self) -> Html<TestComponent> {
pass_helper! { @ html $($content)* }
}
}

View File

@ -21,9 +21,7 @@ impl Component for Child {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!()
}
}
impl Renderable<Self> for Child {
fn view(&self) -> Html<Self> {
unimplemented!()
}
@ -46,9 +44,7 @@ impl Component for ChildContainer {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!()
}
}
impl Renderable<Self> for ChildContainer {
fn view(&self) -> Html<Self> {
unimplemented!()
}

View File

@ -1,53 +1,75 @@
error: this open tag has no corresponding close tag
--> $DIR/html-component-fail.rs:58:13
--> $DIR/html-component-fail.rs:54:13
|
58 | html! { <Child> };
54 | html! { <Child> };
| ^^^^^^^
error: expected identifier
--> $DIR/html-component-fail.rs:59:22
--> $DIR/html-component-fail.rs:55:22
|
59 | html! { <Child:: /> };
55 | html! { <Child:: /> };
| ^
error: this open tag has no corresponding close tag
--> $DIR/html-component-fail.rs:62:13
--> $DIR/html-component-fail.rs:58:13
|
62 | html! { <Child with props > };
58 | html! { <Child with props > };
| ^^^^^^^^^^^^^^^^^^^
error: expected type, found `/`
--> $DIR/html-component-fail.rs:74:14
--> $DIR/html-component-fail.rs:70:14
|
74 | html! { </Child> };
70 | html! { </Child> };
| ^
error: this open tag has no corresponding close tag
--> $DIR/html-component-fail.rs:75:13
--> $DIR/html-component-fail.rs:71:13
|
75 | html! { <Child><Child></Child> };
71 | html! { <Child><Child></Child> };
| ^^^^^^^
error: only one root html element allowed
--> $DIR/html-component-fail.rs:76:28
--> $DIR/html-component-fail.rs:72:28
|
76 | html! { <Child></Child><Child></Child> };
72 | html! { <Child></Child><Child></Child> };
| ^^^^^^^^^^^^^^^
error[E0425]: cannot find value `blah` in this scope
--> $DIR/html-component-fail.rs:63:25
--> $DIR/html-component-fail.rs:59:25
|
63 | html! { <Child with blah /> };
59 | html! { <Child with blah /> };
| ^^^^ not found in this scope
error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:56:5
|
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
56 | html! { <Child with /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:57:5
|
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
57 | html! { <Child props /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:60:5
|
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
60 | html! { <Child with /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^
60 | html! { <Child with props () /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
@ -57,85 +79,63 @@ error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<Chi
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
61 | html! { <Child props /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
61 | html! { <Child type=0 /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:62:5
|
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
62 | html! { <Child invalid-prop-name=0 /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0609]: no field `unknown` on type `ChildProperties`
--> $DIR/html-component-fail.rs:63:20
|
63 | html! { <Child unknown="unknown" /> };
| ^^^^^^^ unknown field
|
= note: available fields are: `string`, `int`
error[E0599]: no method named `unknown` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:63:20
|
5 | #[derive(Properties, PartialEq)]
| - method `unknown` not found for this
...
63 | html! { <Child unknown="unknown" /> };
| ^^^^^^^
error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:64:5
|
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
64 | html! { <Child with props () /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:65:5
|
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
65 | html! { <Child type=0 /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:66:5
|
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
66 | html! { <Child invalid-prop-name=0 /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0609]: no field `unknown` on type `ChildProperties`
--> $DIR/html-component-fail.rs:67:20
|
67 | html! { <Child unknown="unknown" /> };
| ^^^^^^^ unknown field
|
= note: available fields are: `string`, `int`
error[E0599]: no method named `unknown` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:67:20
|
5 | #[derive(Properties, PartialEq)]
| - method `unknown` not found for this
...
67 | html! { <Child unknown="unknown" /> };
| ^^^^^^^
error[E0599]: no method named `build` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:68:5
|
5 | #[derive(Properties, PartialEq)]
| - method `build` not found for this
...
68 | html! { <Child string= /> };
64 | html! { <Child string= /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0308]: mismatched types
--> $DIR/html-component-fail.rs:69:33
--> $DIR/html-component-fail.rs:65:33
|
69 | html! { <Child int=1 string={} /> };
65 | html! { <Child int=1 string={} /> };
| ^^ expected struct `std::string::String`, found ()
|
= note: expected type `std::string::String`
found type `()`
error[E0308]: mismatched types
--> $DIR/html-component-fail.rs:70:33
--> $DIR/html-component-fail.rs:66:33
|
70 | html! { <Child int=1 string=3 /> };
66 | html! { <Child int=1 string=3 /> };
| ^
| |
| expected struct `std::string::String`, found integer
@ -145,9 +145,9 @@ error[E0308]: mismatched types
found type `{integer}`
error[E0308]: mismatched types
--> $DIR/html-component-fail.rs:71:33
--> $DIR/html-component-fail.rs:67:33
|
71 | html! { <Child int=1 string={3} /> };
67 | html! { <Child int=1 string={3} /> };
| ^^^
| |
| expected struct `std::string::String`, found integer
@ -157,71 +157,71 @@ error[E0308]: mismatched types
found type `{integer}`
error[E0308]: mismatched types
--> $DIR/html-component-fail.rs:72:24
--> $DIR/html-component-fail.rs:68:24
|
72 | html! { <Child int=0u32 /> };
68 | html! { <Child int=0u32 /> };
| ^^^^ expected i32, found u32
error[E0599]: no method named `string` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:73:20
--> $DIR/html-component-fail.rs:69:20
|
5 | #[derive(Properties, PartialEq)]
| - method `string` not found for this
...
73 | html! { <Child string="abc" /> };
69 | html! { <Child string="abc" /> };
| ^^^^^^
error[E0599]: no method named `children` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:77:5
--> $DIR/html-component-fail.rs:73:5
|
5 | #[derive(Properties, PartialEq)]
| - method `children` not found for this
...
77 | html! { <Child>{ "Not allowed" }</Child> };
73 | html! { <Child>{ "Not allowed" }</Child> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0277]: the trait bound `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>: std::convert::From<yew::virtual_dom::vnode::VNode<_>>` is not satisfied
--> $DIR/html-component-fail.rs:78:5
--> $DIR/html-component-fail.rs:74:5
|
78 | html! { <ChildContainer>{ "Not allowed" }</ChildContainer> };
74 | html! { <ChildContainer>{ "Not allowed" }</ChildContainer> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<yew::virtual_dom::vnode::VNode<_>>` is not implemented for `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>`
|
= note: required because of the requirements on the impl of `std::convert::Into<yew::virtual_dom::vcomp::VChild<Child, ChildContainer>>` for `yew::virtual_dom::vnode::VNode<_>`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0277]: the trait bound `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>: std::convert::From<yew::virtual_dom::vnode::VNode<_>>` is not satisfied
--> $DIR/html-component-fail.rs:79:5
--> $DIR/html-component-fail.rs:75:5
|
79 | html! { <ChildContainer><></></ChildContainer> };
75 | html! { <ChildContainer><></></ChildContainer> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<yew::virtual_dom::vnode::VNode<_>>` is not implemented for `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>`
|
= note: required because of the requirements on the impl of `std::convert::Into<yew::virtual_dom::vcomp::VChild<Child, ChildContainer>>` for `yew::virtual_dom::vnode::VNode<_>`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0277]: the trait bound `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>: std::convert::From<yew::virtual_dom::vcomp::VChild<ChildContainer, _>>` is not satisfied
--> $DIR/html-component-fail.rs:80:5
--> $DIR/html-component-fail.rs:76:5
|
80 | html! { <ChildContainer><ChildContainer /></ChildContainer> };
76 | html! { <ChildContainer><ChildContainer /></ChildContainer> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<yew::virtual_dom::vcomp::VChild<ChildContainer, _>>` is not implemented for `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>`
|
= note: required because of the requirements on the impl of `std::convert::Into<yew::virtual_dom::vcomp::VChild<Child, ChildContainer>>` for `yew::virtual_dom::vcomp::VChild<ChildContainer, _>`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0277]: the trait bound `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>: std::convert::From<yew::virtual_dom::vcomp::VChild<ChildContainer, _>>` is not satisfied
--> $DIR/html-component-fail.rs:81:5
--> $DIR/html-component-fail.rs:77:5
|
81 | html! { <ChildContainer><ChildContainer /></ChildContainer> };
77 | html! { <ChildContainer><ChildContainer /></ChildContainer> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<yew::virtual_dom::vcomp::VChild<ChildContainer, _>>` is not implemented for `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>`
|
= note: required because of the requirements on the impl of `std::convert::Into<yew::virtual_dom::vcomp::VChild<Child, ChildContainer>>` for `yew::virtual_dom::vcomp::VChild<ChildContainer, _>`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0277]: the trait bound `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>: std::convert::From<yew::virtual_dom::vnode::VNode<_>>` is not satisfied
--> $DIR/html-component-fail.rs:82:5
--> $DIR/html-component-fail.rs:78:5
|
82 | html! { <ChildContainer><Child int=1 /><other /></ChildContainer> };
78 | html! { <ChildContainer><Child int=1 /><other /></ChildContainer> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<yew::virtual_dom::vnode::VNode<_>>` is not implemented for `yew::virtual_dom::vcomp::VChild<Child, ChildContainer>`
|
= note: required because of the requirements on the impl of `std::convert::Into<yew::virtual_dom::vcomp::VChild<Child, ChildContainer>>` for `yew::virtual_dom::vnode::VNode<_>`

View File

@ -26,9 +26,7 @@ impl Component for Child {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!()
}
}
impl Renderable<Child> for Child {
fn view(&self) -> Html<Self> {
unimplemented!()
}
@ -53,9 +51,7 @@ impl Component for Container {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!()
}
}
impl Renderable<Self> for Container {
fn view(&self) -> Html<Self> {
unimplemented!()
}
@ -80,9 +76,7 @@ impl Component for ChildContainer {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!()
}
}
impl Renderable<Self> for ChildContainer {
fn view(&self) -> Html<Self> {
unimplemented!()
}

View File

@ -4,12 +4,12 @@ mod helpers;
use std::iter;
pass_helper! {
html! { for iter::empty::<Html<Self>>() };
html! { for Vec::<Html<Self>>::new().into_iter() };
html! { for iter::empty::<Html<TestComponent>>() };
html! { for Vec::<Html<TestComponent>>::new().into_iter() };
html! { for (0..3).map(|num| { html! { <span>{num}</span> } }) };
html! { for {iter::empty::<Html<Self>>()} };
html! { for {iter::empty::<Html<TestComponent>>()} };
let empty: Vec<Html<Self>> = Vec::new();
let empty: Vec<Html<TestComponent>> = Vec::new();
html! { for empty.into_iter() };
}

View File

@ -18,4 +18,12 @@ impl Component for TestComponent {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!()
}
fn change(&mut self, _: Self::Properties) -> ShouldRender {
unimplemented!()
}
fn view(&self) -> Html<Self> {
unimplemented!()
}
}

View File

@ -2,7 +2,7 @@
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use yew::macros::Properties;
use yew::virtual_dom::VNode;
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);
@ -26,9 +26,7 @@ impl Component for Comp {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}
}
impl Renderable<Comp> for Comp {
fn view(&self) -> Html<Self> {
unimplemented!();
}

View File

@ -1,7 +1,7 @@
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use yew::virtual_dom::VNode;
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);
@ -19,9 +19,7 @@ impl Component for Comp {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}
}
impl Renderable<Comp> for Comp {
fn view(&self) -> Html<Self> {
unimplemented!();
}

View File

@ -5,7 +5,7 @@ use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use yew::html::Scope;
use yew::virtual_dom::vtag::{VTag, HTML_NAMESPACE, SVG_NAMESPACE};
use yew::virtual_dom::{VDiff, VNode};
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);
@ -23,9 +23,7 @@ impl Component for Comp {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}
}
impl Renderable<Comp> for Comp {
fn view(&self) -> Html<Self> {
unimplemented!();
}
@ -44,9 +42,7 @@ impl Component for CompInt {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}
}
impl Renderable<CompInt> for CompInt {
fn view(&self) -> Html<Self> {
unimplemented!();
}
@ -65,9 +61,7 @@ impl Component for CompBool {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}
}
impl Renderable<CompBool> for CompBool {
fn view(&self) -> Html<Self> {
unimplemented!();
}

View File

@ -1,7 +1,7 @@
#[cfg(feature = "wasm_test")]
use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};
use yew::virtual_dom::VNode;
use yew::{html, Component, ComponentLink, Html, Renderable, ShouldRender};
use yew::{html, Component, ComponentLink, Html, ShouldRender};
#[cfg(feature = "wasm_test")]
wasm_bindgen_test_configure!(run_in_browser);
@ -19,9 +19,7 @@ impl Component for Comp {
fn update(&mut self, _: Self::Message) -> ShouldRender {
unimplemented!();
}
}
impl Renderable<Comp> for Comp {
fn view(&self) -> Html<Self> {
unimplemented!();
}