Skip to content

Commit 5ddb34b

Browse files
committed
update to latest yew next
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.
1 parent fa9a925 commit 5ddb34b

File tree

12 files changed

+126
-139
lines changed

12 files changed

+126
-139
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ members = [
1212
"examples/yew-theme-yewdux",
1313
]
1414
resolver = "2"
15+
16+
[patch.crates-io]
17+
yew = { git = "https://github.com/yewstack/yew", rev = "7a55441daed1b154df47077133e377120a23de75" }
18+
yew-agent = { git = "https://github.com/yewstack/yew", rev = "7a55441daed1b154df47077133e377120a23de75" }
19+
yewdux = { git = "https://github.com/intendednull/yewdux", rev = "d844ab9918ff0eaae59be57cce3773ed33f72dca" }

examples/benchmarks/src/main.rs

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub enum BenchMsg {
3434
}
3535

3636
pub struct Benchmarks {
37-
link: ComponentLink<Self>,
3837
finished: bool,
3938

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

59-
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
58+
fn create(_: &Context<Self>) -> Self {
6059
Self {
61-
link,
6260
finished: false,
6361
parse_simple: None,
6462
macro_simple: None,
@@ -74,45 +72,45 @@ impl Component for Benchmarks {
7472
}
7573
}
7674

77-
fn rendered(&mut self, first_render: bool) {
75+
fn rendered(&mut self, ctx: &Context<Self>, first_render: bool) {
7876
if first_render {
79-
let cb = self
80-
.link
77+
let cb = ctx
78+
.link()
8179
.callback(|_| BenchMsg::ParseSimpleFinish(benchmarks::bench_parse_simple()));
8280
Timeout::new(100, move || cb.emit(())).forget();
8381
}
8482
}
8583

86-
fn update(&mut self, msg: Self::Message) -> ShouldRender {
84+
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
8785
match msg {
8886
BenchMsg::ParseSimpleFinish(m) => {
8987
self.parse_simple = Some(m);
90-
let cb = self
91-
.link
88+
let cb = ctx
89+
.link()
9290
.callback(|_| BenchMsg::MacroSimpleFinish(benchmarks::bench_macro_simple()));
9391

9492
Timeout::new(100, move || cb.emit(())).forget();
9593
}
9694
BenchMsg::MacroSimpleFinish(m) => {
9795
self.macro_simple = Some(m);
98-
let cb = self.link.callback(|_| {
96+
let cb = ctx.link().callback(|_| {
9997
BenchMsg::MacroInlineSimpleFinish(benchmarks::bench_macro_inline_simple())
10098
});
10199

102100
Timeout::new(100, move || cb.emit(())).forget();
103101
}
104102
BenchMsg::MacroInlineSimpleFinish(m) => {
105103
self.macro_inline_simple = Some(m);
106-
let cb = self.link.callback(|_| {
104+
let cb = ctx.link().callback(|_| {
107105
BenchMsg::ParseSimpleNoCacheFinish(benchmarks::bench_parse_simple_no_cache())
108106
});
109107

110108
Timeout::new(100, move || cb.emit(())).forget();
111109
}
112110
BenchMsg::ParseSimpleNoCacheFinish(m) => {
113111
self.parse_simple_no_cache = Some(m);
114-
let cb = self
115-
.link
112+
let cb = ctx
113+
.link()
116114
.callback(|_| BenchMsg::ParseComplexFinish(benchmarks::bench_parse_complex()));
117115

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

124-
let cb = self
125-
.link
122+
let cb = ctx
123+
.link()
126124
.callback(|_| BenchMsg::MacroComplexFinish(benchmarks::bench_macro_complex()));
127125

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

133-
let cb = self.link.callback(|_| {
131+
let cb = ctx.link().callback(|_| {
134132
BenchMsg::MacroInlineComplexFinish(benchmarks::bench_macro_inline_complex())
135133
});
136134

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

142-
let cb = self.link.callback(|_| {
140+
let cb = ctx.link().callback(|_| {
143141
BenchMsg::ParseComplexNoCacheFinish(benchmarks::bench_parse_complex_no_cache())
144142
});
145143

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

151-
let cb = self
152-
.link
149+
let cb = ctx
150+
.link()
153151
.callback(|_| BenchMsg::CachedLookupFinish(benchmarks::bench_cached_lookup()));
154152

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

161159
let cb =
162-
self.link.callback(|_| {
160+
ctx.link().callback(|_| {
163161
BenchMsg::CachedLookupBigSheetFinish(
164162
benchmarks::bench_cached_lookup_big_sheet(),
165163
)
@@ -171,8 +169,8 @@ impl Component for Benchmarks {
171169
BenchMsg::CachedLookupBigSheetFinish(m) => {
172170
self.cached_lookup_big_sheet = Some(m);
173171

174-
let cb = self
175-
.link
172+
let cb = ctx
173+
.link()
176174
.callback(|_| BenchMsg::MountingFinish(benchmarks::bench_mounting()));
177175

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

189-
fn change(&mut self, _: Self::Properties) -> ShouldRender {
187+
fn changed(&mut self, _: &Context<Self>) -> bool {
190188
false
191189
}
192190

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

318316
pub struct App {
319-
link: ComponentLink<Self>,
320317
started: bool,
321318
}
322319

323320
impl Component for App {
324321
type Message = AppMsg;
325322
type Properties = ();
326323

327-
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
328-
Self {
329-
link,
330-
started: false,
331-
}
324+
fn create(_: &Context<Self>) -> Self {
325+
Self { started: false }
332326
}
333327

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

337331
self.started = true;
338332

339333
true
340334
}
341335

342-
fn change(&mut self, _: Self::Properties) -> ShouldRender {
336+
fn changed(&mut self, _: &Context<Self>) -> bool {
343337
false
344338
}
345339

346-
fn view(&self) -> Html {
340+
fn view(&self, ctx: &Context<Self>) -> Html {
347341
html! {
348342
<>
349-
<Global css=GLOBAL_STYLE />
350-
<div class=self.style()>
343+
<Global css={GLOBAL_STYLE} />
344+
<div class={self.style()}>
351345
<h1>{"Stylist Benchmark"}</h1>
352346
{
353347
if self.started {
@@ -356,7 +350,7 @@ impl Component for App {
356350
html!{
357351
<>
358352
<div class="before-intro">{"To start benchmarking, please click start:"}</div>
359-
<button onclick=self.link.callback(|_| AppMsg::Start)>
353+
<button onclick={ctx.link().callback(|_| AppMsg::Start)}>
360354
{"Start!"}
361355
</button>
362356
</>

examples/proc-macros/src/main.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use stylist::css;
2-
use stylist::yew::Global;
3-
use yew::{html, Component, ComponentLink, Html, ShouldRender};
1+
use stylist::{css, yew::Global};
2+
use yew::{html, Component, Context, Html};
43

54
use log::Level;
65

@@ -13,21 +12,21 @@ impl Component for Inside {
1312
type Message = ();
1413
type Properties = ();
1514

16-
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
15+
fn create(_: &Context<Self>) -> Self {
1716
Self {}
1817
}
1918

20-
fn update(&mut self, _: Self::Message) -> ShouldRender {
19+
fn update(&mut self, _: &Context<Self>, _: Self::Message) -> bool {
2120
false
2221
}
2322

24-
fn change(&mut self, _: Self::Properties) -> ShouldRender {
23+
fn changed(&mut self, _: &Context<Self>) -> bool {
2524
false
2625
}
2726

28-
fn view(&self) -> Html {
27+
fn view(&self, _: &Context<Self>) -> Html {
2928
html! {
30-
<div class=css!(
29+
<div class={css!(
3130
r#"
3231
width: ${size}px;
3332
height: ${size}px;
@@ -42,7 +41,7 @@ impl Component for Inside {
4241
color: white;
4342
"#,
4443
size = 200,
45-
)>
44+
)}>
4645
{"The quick brown fox jumps over the lazy dog"}
4746
</div>
4847
}
@@ -55,22 +54,22 @@ impl Component for App {
5554
type Message = ();
5655
type Properties = ();
5756

58-
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
57+
fn create(_: &Context<Self>) -> Self {
5958
Self {}
6059
}
6160

62-
fn update(&mut self, _: Self::Message) -> ShouldRender {
61+
fn update(&mut self, _: &Context<Self>, _: Self::Message) -> bool {
6362
false
6463
}
6564

66-
fn change(&mut self, _: Self::Properties) -> ShouldRender {
65+
fn changed(&mut self, _: &Context<Self>) -> bool {
6766
false
6867
}
6968

70-
fn view(&self) -> Html {
69+
fn view(&self, _: &Context<Self>) -> Html {
7170
html! {
7271
<>
73-
<Global css=css!(r#"
72+
<Global css={css!(r#"
7473
html, body {
7574
font-family: sans-serif;
7675
@@ -85,9 +84,9 @@ impl Component for App {
8584
8685
background-color: rgb(237, 244, 255);
8786
}
88-
"#) />
87+
"#)} />
8988
<h1>{"Procedural Macro Example"}</h1>
90-
<div class=css!(r#"
89+
<div class={css!(r#"
9190
box-shadow: 0 0 5px 1px rgba(0, 0, 0, 0.7);
9291
height: 500px;
9392
width: 500px;
@@ -102,7 +101,7 @@ impl Component for App {
102101
103102
flex-direction: column;
104103
background-color: white;
105-
"#) >
104+
"#)} >
106105
{"The quick brown fox jumps over the lazy dog"}
107106
<Inside />
108107
</div>

0 commit comments

Comments
 (0)