Skip to content

Commit

Permalink
update to latest yew next
Browse files Browse the repository at this point in the history
Not yet fully functional, due to yewdux not having upgraded to
yewstack/yew#1961. Specifically, some examples are not working,
but the stylist packages are fine.
  • Loading branch information
WorldSEnder committed Aug 31, 2021
1 parent fa9a925 commit 5ddb34b
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 139 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ members = [
"examples/yew-theme-yewdux",
]
resolver = "2"

[patch.crates-io]
yew = { git = "https://github.com/yewstack/yew", rev = "7a55441daed1b154df47077133e377120a23de75" }
yew-agent = { git = "https://github.com/yewstack/yew", rev = "7a55441daed1b154df47077133e377120a23de75" }
yewdux = { git = "https://github.com/intendednull/yewdux", rev = "d844ab9918ff0eaae59be57cce3773ed33f72dca" }
68 changes: 31 additions & 37 deletions examples/benchmarks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub enum BenchMsg {
}

pub struct Benchmarks {
link: ComponentLink<Self>,
finished: bool,

parse_simple: Option<f64>,
Expand All @@ -56,9 +55,8 @@ impl Component for Benchmarks {
type Message = BenchMsg;
type Properties = ();

fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
fn create(_: &Context<Self>) -> Self {
Self {
link,
finished: false,
parse_simple: None,
macro_simple: None,
Expand All @@ -74,45 +72,45 @@ impl Component for Benchmarks {
}
}

fn rendered(&mut self, first_render: bool) {
fn rendered(&mut self, ctx: &Context<Self>, first_render: bool) {
if first_render {
let cb = self
.link
let cb = ctx
.link()
.callback(|_| BenchMsg::ParseSimpleFinish(benchmarks::bench_parse_simple()));
Timeout::new(100, move || cb.emit(())).forget();
}
}

fn update(&mut self, msg: Self::Message) -> ShouldRender {
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg {
BenchMsg::ParseSimpleFinish(m) => {
self.parse_simple = Some(m);
let cb = self
.link
let cb = ctx
.link()
.callback(|_| BenchMsg::MacroSimpleFinish(benchmarks::bench_macro_simple()));

Timeout::new(100, move || cb.emit(())).forget();
}
BenchMsg::MacroSimpleFinish(m) => {
self.macro_simple = Some(m);
let cb = self.link.callback(|_| {
let cb = ctx.link().callback(|_| {
BenchMsg::MacroInlineSimpleFinish(benchmarks::bench_macro_inline_simple())
});

Timeout::new(100, move || cb.emit(())).forget();
}
BenchMsg::MacroInlineSimpleFinish(m) => {
self.macro_inline_simple = Some(m);
let cb = self.link.callback(|_| {
let cb = ctx.link().callback(|_| {
BenchMsg::ParseSimpleNoCacheFinish(benchmarks::bench_parse_simple_no_cache())
});

Timeout::new(100, move || cb.emit(())).forget();
}
BenchMsg::ParseSimpleNoCacheFinish(m) => {
self.parse_simple_no_cache = Some(m);
let cb = self
.link
let cb = ctx
.link()
.callback(|_| BenchMsg::ParseComplexFinish(benchmarks::bench_parse_complex()));

Timeout::new(100, move || cb.emit(())).forget();
Expand All @@ -121,16 +119,16 @@ impl Component for Benchmarks {
BenchMsg::ParseComplexFinish(m) => {
self.parse_complex = Some(m);

let cb = self
.link
let cb = ctx
.link()
.callback(|_| BenchMsg::MacroComplexFinish(benchmarks::bench_macro_complex()));

Timeout::new(100, move || cb.emit(())).forget();
}
BenchMsg::MacroComplexFinish(m) => {
self.macro_complex = Some(m);

let cb = self.link.callback(|_| {
let cb = ctx.link().callback(|_| {
BenchMsg::MacroInlineComplexFinish(benchmarks::bench_macro_inline_complex())
});

Expand All @@ -139,7 +137,7 @@ impl Component for Benchmarks {
BenchMsg::MacroInlineComplexFinish(m) => {
self.macro_inline_complex = Some(m);

let cb = self.link.callback(|_| {
let cb = ctx.link().callback(|_| {
BenchMsg::ParseComplexNoCacheFinish(benchmarks::bench_parse_complex_no_cache())
});

Expand All @@ -148,8 +146,8 @@ impl Component for Benchmarks {
BenchMsg::ParseComplexNoCacheFinish(m) => {
self.parse_complex_no_cache = Some(m);

let cb = self
.link
let cb = ctx
.link()
.callback(|_| BenchMsg::CachedLookupFinish(benchmarks::bench_cached_lookup()));

Timeout::new(100, move || cb.emit(())).forget();
Expand All @@ -159,7 +157,7 @@ impl Component for Benchmarks {
self.cached_lookup = Some(m);

let cb =
self.link.callback(|_| {
ctx.link().callback(|_| {
BenchMsg::CachedLookupBigSheetFinish(
benchmarks::bench_cached_lookup_big_sheet(),
)
Expand All @@ -171,8 +169,8 @@ impl Component for Benchmarks {
BenchMsg::CachedLookupBigSheetFinish(m) => {
self.cached_lookup_big_sheet = Some(m);

let cb = self
.link
let cb = ctx
.link()
.callback(|_| BenchMsg::MountingFinish(benchmarks::bench_mounting()));

Timeout::new(100, move || cb.emit(())).forget();
Expand All @@ -186,13 +184,13 @@ impl Component for Benchmarks {
true
}

fn change(&mut self, _: Self::Properties) -> ShouldRender {
fn changed(&mut self, _: &Context<Self>) -> bool {
false
}

fn view(&self) -> Html {
fn view(&self, _: &Context<Self>) -> Html {
html! {
<div class=self.style()>
<div class={self.style()}>
{
if !self.finished {
html!{<div class="running">{"Benchmarking..."}<br />{"The browser may be unresponsive during the benchmark."}</div>}
Expand Down Expand Up @@ -316,38 +314,34 @@ pub enum AppMsg {
}

pub struct App {
link: ComponentLink<Self>,
started: bool,
}

impl Component for App {
type Message = AppMsg;
type Properties = ();

fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
Self {
link,
started: false,
}
fn create(_: &Context<Self>) -> Self {
Self { started: false }
}

fn update(&mut self, msg: Self::Message) -> ShouldRender {
fn update(&mut self, _: &Context<Self>, msg: Self::Message) -> bool {
assert_eq!(msg, AppMsg::Start);

self.started = true;

true
}

fn change(&mut self, _: Self::Properties) -> ShouldRender {
fn changed(&mut self, _: &Context<Self>) -> bool {
false
}

fn view(&self) -> Html {
fn view(&self, ctx: &Context<Self>) -> Html {
html! {
<>
<Global css=GLOBAL_STYLE />
<div class=self.style()>
<Global css={GLOBAL_STYLE} />
<div class={self.style()}>
<h1>{"Stylist Benchmark"}</h1>
{
if self.started {
Expand All @@ -356,7 +350,7 @@ impl Component for App {
html!{
<>
<div class="before-intro">{"To start benchmarking, please click start:"}</div>
<button onclick=self.link.callback(|_| AppMsg::Start)>
<button onclick={ctx.link().callback(|_| AppMsg::Start)}>
{"Start!"}
</button>
</>
Expand Down
33 changes: 16 additions & 17 deletions examples/proc-macros/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use stylist::css;
use stylist::yew::Global;
use yew::{html, Component, ComponentLink, Html, ShouldRender};
use stylist::{css, yew::Global};
use yew::{html, Component, Context, Html};

use log::Level;

Expand All @@ -13,21 +12,21 @@ impl Component for Inside {
type Message = ();
type Properties = ();

fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
fn create(_: &Context<Self>) -> Self {
Self {}
}

fn update(&mut self, _: Self::Message) -> ShouldRender {
fn update(&mut self, _: &Context<Self>, _: Self::Message) -> bool {
false
}

fn change(&mut self, _: Self::Properties) -> ShouldRender {
fn changed(&mut self, _: &Context<Self>) -> bool {
false
}

fn view(&self) -> Html {
fn view(&self, _: &Context<Self>) -> Html {
html! {
<div class=css!(
<div class={css!(
r#"
width: ${size}px;
height: ${size}px;
Expand All @@ -42,7 +41,7 @@ impl Component for Inside {
color: white;
"#,
size = 200,
)>
)}>
{"The quick brown fox jumps over the lazy dog"}
</div>
}
Expand All @@ -55,22 +54,22 @@ impl Component for App {
type Message = ();
type Properties = ();

fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
fn create(_: &Context<Self>) -> Self {
Self {}
}

fn update(&mut self, _: Self::Message) -> ShouldRender {
fn update(&mut self, _: &Context<Self>, _: Self::Message) -> bool {
false
}

fn change(&mut self, _: Self::Properties) -> ShouldRender {
fn changed(&mut self, _: &Context<Self>) -> bool {
false
}

fn view(&self) -> Html {
fn view(&self, _: &Context<Self>) -> Html {
html! {
<>
<Global css=css!(r#"
<Global css={css!(r#"
html, body {
font-family: sans-serif;
Expand All @@ -85,9 +84,9 @@ impl Component for App {
background-color: rgb(237, 244, 255);
}
"#) />
"#)} />
<h1>{"Procedural Macro Example"}</h1>
<div class=css!(r#"
<div class={css!(r#"
box-shadow: 0 0 5px 1px rgba(0, 0, 0, 0.7);
height: 500px;
width: 500px;
Expand All @@ -102,7 +101,7 @@ impl Component for App {
flex-direction: column;
background-color: white;
"#) >
"#)} >
{"The quick brown fox jumps over the lazy dog"}
<Inside />
</div>
Expand Down
Loading

0 comments on commit 5ddb34b

Please sign in to comment.