Skip to content

Commit b3f8ca1

Browse files
authored
Replace Model with App or MyComponent (yewstack#2336)
`Model` is ambiguous and not a user-friendly name. Some of the newer docs are already referring to the root component as `App`. This PR follows this naming scheme: - `App` for a root component - `MyComponent` for an arbitrary component This naming is inspired by the React docs. i18n references were not changed. They need a larger rewrite which will go in a separate PR.
1 parent 76010d1 commit b3f8ca1

File tree

25 files changed

+100
-100
lines changed

25 files changed

+100
-100
lines changed

CHANGELOG.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -550,18 +550,18 @@ This is the main painful breaking change. It applies to both element listeners a
550550

551551
Before:
552552
```rust
553-
struct Model;
553+
struct MyComponent;
554554

555555
enum Msg {
556556
Click,
557557
}
558558

559-
impl Component for Model {
559+
impl Component for MyComponent {
560560
type Message = Msg;
561561
type Properties = ();
562562

563563
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
564-
Model
564+
MyComponent
565565
}
566566

567567
fn update(&mut self, msg: Self::Message) -> ShouldRender {
@@ -581,20 +581,20 @@ impl Component for Model {
581581

582582
After:
583583
```rust
584-
struct Model {
584+
struct MyComponent {
585585
link: ComponentLink<Self>,
586586
}
587587

588588
enum Msg {
589589
Click,
590590
}
591591

592-
impl Component for Model {
592+
impl Component for MyComponent {
593593
type Message = Msg;
594594
type Properties = ();
595595

596596
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
597-
Model { link }
597+
MyComponent { link }
598598
}
599599

600600
fn update(&mut self, msg: Self::Message) -> ShouldRender {
@@ -653,7 +653,7 @@ was confusing and restrictive and is now a thing of the past!
653653

654654
Before:
655655
```rust
656-
impl Component for Model {
656+
impl Component for MyComponent {
657657
// ...
658658

659659
fn view(&self) -> Html<Self> {
@@ -664,7 +664,7 @@ impl Component for Model {
664664

665665
After:
666666
```rust
667-
impl Component for Model {
667+
impl Component for MyComponent {
668668
// ...
669669

670670
fn view(&self) -> Html {
@@ -688,20 +688,20 @@ cloned is when a wrapper component re-renders nested children components.
688688
- The `html!` macro now accepts a `Callback` for element listeners. [[@jstarry], [#777](https://github.com/yewstack/yew/pull/777)]
689689

690690
```rust
691-
struct Model {
691+
struct MyComponent {
692692
onclick: Callback<ClickEvent>,
693693
}
694694

695695
enum Msg {
696696
Click,
697697
}
698698

699-
impl Component for Model {
699+
impl Component for MyComponent {
700700
type Message = Msg;
701701
type Properties = ();
702702

703703
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
704-
Model {
704+
MyComponent {
705705
onclick: link.callback(|_| Msg::Click),
706706
}
707707
}
@@ -875,20 +875,20 @@ cloned is when a wrapper component re-renders nested children components.
875875

876876
Before:
877877
```rust
878-
impl Component for Model {
878+
impl Component for MyComponent {
879879
type Message = Msg;
880880
type Properties = ();
881881

882882
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
883-
Model {}
883+
MyComponent {}
884884
}
885885

886886
fn update(&mut self, msg: Self::Message) -> ShouldRender {
887887
true
888888
}
889889
}
890890

891-
impl Renderable<Model> for Model {
891+
impl Renderable<MyComponent> for MyComponent {
892892
fn view(&self) -> Html<Self> {
893893
html! { "hello" }
894894
}
@@ -897,12 +897,12 @@ cloned is when a wrapper component re-renders nested children components.
897897

898898
After:
899899
```rust
900-
impl Component for Model {
900+
impl Component for MyComponent {
901901
type Message = Msg;
902902
type Properties = ();
903903

904904
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
905-
Model {}
905+
MyComponent {}
906906
}
907907

908908
fn update(&mut self, msg: Self::Message) -> ShouldRender {

examples/agents/src/bin/app.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
fn main() {
22
wasm_logger::init(wasm_logger::Config::default());
3-
yew::start_app::<agents::Model>();
3+
yew::start_app::<agents::App>();
44
}

examples/agents/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ pub enum Msg {
99
DataReceived,
1010
}
1111

12-
pub struct Model {
12+
pub struct App {
1313
worker: Box<dyn Bridge<native_worker::Worker>>,
1414
}
1515

16-
impl Component for Model {
16+
impl Component for App {
1717
type Message = Msg;
1818
type Properties = ();
1919

examples/boids/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ pub enum Msg {
1717
TogglePause,
1818
}
1919

20-
pub struct Model {
20+
pub struct App {
2121
settings: Settings,
2222
generation: usize,
2323
paused: bool,
2424
}
25-
impl Component for Model {
25+
impl Component for App {
2626
type Message = Msg;
2727
type Properties = ();
2828

@@ -74,7 +74,7 @@ impl Component for Model {
7474
}
7575
}
7676
}
77-
impl Model {
77+
impl App {
7878
fn view_panel(&self, link: &Scope<Self>) -> Html {
7979
let pause_text = if self.paused { "Resume" } else { "Pause" };
8080
html! {
@@ -162,5 +162,5 @@ impl Model {
162162
}
163163

164164
fn main() {
165-
yew::start_app::<Model>();
165+
yew::start_app::<App>();
166166
}

examples/contexts/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use yew::prelude::*;
99
use msg_ctx::MessageProvider;
1010

1111
#[function_component]
12-
pub fn Model() -> Html {
12+
pub fn App() -> Html {
1313
html! {
1414
<MessageProvider>
1515
<Producer />
@@ -19,5 +19,5 @@ pub fn Model() -> Html {
1919
}
2020

2121
fn main() {
22-
yew::start_app::<Model>();
22+
yew::start_app::<App>();
2323
}

examples/counter/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ pub enum Msg {
88
Decrement,
99
}
1010

11-
pub struct Model {
11+
pub struct App {
1212
value: i64, // This will store the counter value
1313
}
1414

15-
impl Component for Model {
15+
impl Component for App {
1616
type Message = Msg;
1717
type Properties = ();
1818

@@ -72,5 +72,5 @@ impl Component for Model {
7272
}
7373

7474
fn main() {
75-
yew::start_app::<Model>();
75+
yew::start_app::<App>();
7676
}

examples/dyn_create_destroy_apps/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ pub enum Msg {
1515
DestroyCounterApp(usize),
1616
}
1717

18-
pub struct Model {
18+
pub struct App {
1919
apps: Slab<(Element, AppHandle<CounterModel>)>, // Contains the spawned apps and their parent div elements
2020
apps_container_ref: NodeRef,
2121
}
2222

23-
impl Component for Model {
23+
impl Component for App {
2424
type Message = Msg;
2525
type Properties = ();
2626

@@ -107,5 +107,5 @@ impl Component for Model {
107107

108108
fn main() {
109109
// Start main app
110-
yew::start_app::<Model>();
110+
yew::start_app::<App>();
111111
}

examples/file_upload/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ pub enum Msg {
1515
ToggleReadBytes,
1616
}
1717

18-
pub struct Model {
18+
pub struct App {
1919
readers: HashMap<String, FileReader>,
2020
files: Vec<String>,
2121
read_bytes: bool,
2222
}
2323

24-
impl Component for Model {
24+
impl Component for App {
2525
type Message = Msg;
2626
type Properties = ();
2727

@@ -115,7 +115,7 @@ impl Component for Model {
115115
}
116116
}
117117

118-
impl Model {
118+
impl App {
119119
fn view_file(data: &str) -> Html {
120120
html! {
121121
<li>{ data }</li>
@@ -124,5 +124,5 @@ impl Model {
124124
}
125125

126126
fn main() {
127-
yew::start_app::<Model>();
127+
yew::start_app::<App>();
128128
}

examples/futures/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ enum Msg {
6363
GetMarkdown,
6464
GetError,
6565
}
66-
struct Model {
66+
struct App {
6767
markdown: FetchState<String>,
6868
}
6969

70-
impl Component for Model {
70+
impl Component for App {
7171
type Message = Msg;
7272
type Properties = ();
7373

@@ -128,5 +128,5 @@ impl Component for Model {
128128
}
129129

130130
fn main() {
131-
yew::start_app::<Model>();
131+
yew::start_app::<App>();
132132
}

examples/game_of_life/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ pub enum Msg {
1616
Tick,
1717
}
1818

19-
pub struct Model {
19+
pub struct App {
2020
active: bool,
2121
cellules: Vec<Cellule>,
2222
cellules_width: usize,
2323
cellules_height: usize,
2424
_interval: Interval,
2525
}
2626

27-
impl Model {
27+
impl App {
2828
pub fn random_mutate(&mut self) {
2929
for cellule in self.cellules.iter_mut() {
3030
if rand::thread_rng().gen() {
@@ -101,7 +101,7 @@ impl Model {
101101
}
102102
}
103103
}
104-
impl Component for Model {
104+
impl Component for App {
105105
type Message = Msg;
106106
type Properties = ();
107107

@@ -226,5 +226,5 @@ fn wrap(coord: isize, range: isize) -> usize {
226226
fn main() {
227227
wasm_logger::init(wasm_logger::Config::default());
228228
log::trace!("Initializing yew...");
229-
yew::start_app::<Model>();
229+
yew::start_app::<App>();
230230
}

examples/inner_html/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use yew::{Component, Context, Html};
33

44
const HTML: &str = include_str!("document.html");
55

6-
pub struct Model {
6+
pub struct App {
77
pub value: i64,
88
}
99

10-
impl Component for Model {
10+
impl Component for App {
1111
type Message = ();
1212
type Properties = ();
1313

@@ -26,5 +26,5 @@ impl Component for Model {
2626
}
2727

2828
fn main() {
29-
yew::start_app::<Model>();
29+
yew::start_app::<App>();
3030
}

examples/js_callback/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ pub enum Msg {
99
AsyncPayload,
1010
}
1111

12-
pub struct Model {
12+
pub struct App {
1313
payload: String,
1414
// Pointless field just to have something that's been manipulated
1515
debugged_payload: String,
1616
}
1717

18-
impl Component for Model {
18+
impl Component for App {
1919
type Message = Msg;
2020
type Properties = ();
2121

@@ -73,5 +73,5 @@ impl Component for Model {
7373
}
7474

7575
fn main() {
76-
yew::start_app::<Model>();
76+
yew::start_app::<App>();
7777
}

0 commit comments

Comments
 (0)