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

Fix pub_sub example that no longer compiles in 0.13 #989

Merged
merged 1 commit into from
Mar 12, 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 examples/pub_sub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ edition = "2018"
log = "0.4"
web_logger = "0.1"
serde = { version = "1.0", features = ["derive"] }
yew = { path = "../.." }
yew = { path = "../..", features = ["std_web"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually stdweb isn't needed as an explicit dependency. My preferred fix would be to:

  1. Remove stdweb dependency
  2. Follow the other stdweb/web-sys agnostic examples and setup the Cargo.toml like this:
yew = { path = "../.." }

[features]
std_web = ["yew/std_web"]
web_sys = ["yew/web_sys"]

Copy link
Contributor Author

@totorigolo totorigolo Mar 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find how to start an example that uses web_sys. Can you link to some instructions? :)

EDIT: I just saw yewstack/docs#34 that is related to this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@totorigolo you can also check out this build script (although it's kinda broken atm) https://github.com/yewstack/yew/blob/master/examples/build_all.sh

stdweb = "0.4.20"
1 change: 0 additions & 1 deletion examples/pub_sub/src/event_bus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use std::fmt::Debug;
use yew::worker::*;

#[derive(Serialize, Deserialize, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions examples/pub_sub/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod producer;
mod subscriber;

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

pub struct Model {}
Expand All @@ -26,7 +26,7 @@ impl Component for Model {
html! {
<div>
<Producer />
<Subsciber />
<Subscriber />
</div>
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/pub_sub/src/producer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Component for Producer {
match msg {
Msg::Clicked => {
self.event_bus
.send(Request::EventBusMsg(format!("Message receieved")));
.send(Request::EventBusMsg(format!("Message received")));
false
}
}
Expand Down
10 changes: 5 additions & 5 deletions examples/pub_sub/src/subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ pub enum Msg {
NewMessage(String),
}

pub struct Subsciber {
pub struct Subscriber {
message: String,
_producer: Box<dyn Bridge<EventBus>>,
}

impl Component for Subsciber {
impl Component for Subscriber {
type Message = Msg;
type Properties = ();

fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
let callback = link.callback(|s| Msg::NewMessage(s));
let _producer = EventBus::bridge(callback);
Subsciber {
message: format!("No message yet"),
Subscriber {
message: format!("No message yet."),
_producer,
}
}
Expand All @@ -33,7 +33,7 @@ impl Component for Subsciber {

fn view(&self) -> Html {
html! {
<h1>{self.message.clone()}</h1>
<h1>{ &self.message }</h1>
}
}
}