Skip to content

Commit 4a14d0f

Browse files
Xavientoisteymour-aldridgemc1098
authored
Add requirement for braces around most props (#1939)
* Limit the properties to literals and brace-enclosed expressions * Update examples with new syntax * Update packages/yew-macro/src/props/prop.rs Co-authored-by: Teymour Aldridge <[email protected]> * Fix lints and strip braces around single expressions * Update docs with new prop syntax * Add some test cases for new syntax * Ensure all tests are passing * Clean up missed code * Update tests * Update reverted docs * Revert versioned docs * Fix optional attributes paragraph * Remove accidentally added files * Remove accidentally added french docs * Update packages/yew-macro/src/props/prop.rs Co-authored-by: mc1098 <[email protected]> * Fix forgotten braces and test cases * Revert i18n old docs * Revert translated docs * Remove suggested fix in favour of more succinct error message * Update errors after rebase * Remove files accidentally added while rebasing * Fix merge conflicts Co-authored-by: Teymour Aldridge <[email protected]> Co-authored-by: mc1098 <[email protected]>
1 parent d89f1cc commit 4a14d0f

File tree

91 files changed

+544
-603
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+544
-603
lines changed

examples/boids/src/boid.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl Boid {
130130
points.push_str(&format!("{:.2},{:.2} ", x, y));
131131
}
132132

133-
html! { <polygon points=points fill=color /> }
133+
html! { <polygon points={points} fill={color} /> }
134134
}
135135
}
136136

examples/boids/src/main.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Component for Model {
7373
html! {
7474
<>
7575
<h1 class="title">{ "Boids" }</h1>
76-
<Simulation settings=settings.clone() generation=generation paused=paused />
76+
<Simulation settings={settings.clone()} generation={generation} paused={paused} />
7777
{ self.view_panel() }
7878
</>
7979
}
@@ -87,9 +87,9 @@ impl Model {
8787
<div class="panel">
8888
{ self.view_settings() }
8989
<div class="panel__buttons">
90-
<button onclick=link.callback(|_| Msg::TogglePause)>{ pause_text }</button>
91-
<button onclick=link.callback(|_| Msg::ResetSettings)>{ "Use Defaults" }</button>
92-
<button onclick=link.callback(|_| Msg::RestartSimulation)>{ "Restart" }</button>
90+
<button onclick={link.callback(|_| Msg::TogglePause)}>{ pause_text }</button>
91+
<button onclick={link.callback(|_| Msg::ResetSettings)}>{ "Use Defaults" }</button>
92+
<button onclick={link.callback(|_| Msg::RestartSimulation)}>{ "Restart" }</button>
9393
</div>
9494
</div>
9595
}
@@ -119,48 +119,48 @@ impl Model {
119119
<div class="settings">
120120
<Slider label="Number of Boids"
121121
min=1.0 max=600.0
122-
onchange=settings_callback!(link, settings; boids as usize)
123-
value=settings.boids as f64
122+
onchange={settings_callback!(link, settings; boids as usize)}
123+
value={settings.boids as f64}
124124
/>
125125
<Slider label="View Distance"
126126
max=500.0 step=10.0
127-
onchange=settings_callback!(link, settings; visible_range)
128-
value=settings.visible_range
127+
onchange={settings_callback!(link, settings; visible_range)}
128+
value={settings.visible_range}
129129
/>
130130
<Slider label="Spacing"
131131
max=100.0
132-
onchange=settings_callback!(link, settings; min_distance)
133-
value=settings.min_distance
132+
onchange={settings_callback!(link, settings; min_distance)}
133+
value={settings.min_distance}
134134
/>
135135
<Slider label="Max Speed"
136136
max=50.0
137-
onchange=settings_callback!(link, settings; max_speed)
138-
value=settings.max_speed
137+
onchange={settings_callback!(link, settings; max_speed)}
138+
value={settings.max_speed}
139139
/>
140140
<Slider label="Cohesion"
141141
max=0.5 percentage=true
142-
onchange=settings_callback!(link, settings; cohesion_factor)
143-
value=settings.cohesion_factor
142+
onchange={settings_callback!(link, settings; cohesion_factor)}
143+
value={settings.cohesion_factor}
144144
/>
145145
<Slider label="Separation"
146146
max=1.0 percentage=true
147-
onchange=settings_callback!(link, settings; separation_factor)
148-
value=settings.separation_factor
147+
onchange={settings_callback!(link, settings; separation_factor)}
148+
value={settings.separation_factor}
149149
/>
150150
<Slider label="Alignment"
151151
max=0.5 percentage=true
152-
onchange=settings_callback!(link, settings; alignment_factor)
153-
value=settings.alignment_factor
152+
onchange={settings_callback!(link, settings; alignment_factor)}
153+
value={settings.alignment_factor}
154154
/>
155155
<Slider label="Turn Speed"
156156
max=1.5 percentage=true
157-
onchange=settings_callback!(link, settings; turn_speed_ratio)
158-
value=settings.turn_speed_ratio
157+
onchange={settings_callback!(link, settings; turn_speed_ratio)}
158+
value={settings.turn_speed_ratio}
159159
/>
160160
<Slider label="Color Adaption"
161161
max=1.5 percentage=true
162-
onchange=settings_callback!(link, settings; color_adapt_factor)
163-
value=settings.color_adapt_factor
162+
onchange={settings_callback!(link, settings; color_adapt_factor)}
163+
value={settings.color_adapt_factor}
164164
/>
165165
</div>
166166
}

examples/boids/src/simulation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Component for Simulation {
104104
let view_box = format!("0 0 {} {}", SIZE.x, SIZE.y);
105105

106106
html! {
107-
<svg class="simulation-window" viewBox=view_box>
107+
<svg class="simulation-window" viewBox={view_box}>
108108
{ for self.boids.iter().map(Boid::render) }
109109
</svg>
110110
}

examples/boids/src/slider.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ impl Component for Slider {
8080

8181
html! {
8282
<div class="slider">
83-
<label for=id.clone() class="slider__label">{ label }</label>
83+
<label for={id.clone()} class="slider__label">{ label }</label>
8484
<input type="range"
85-
id=id
85+
id={id}
8686
class="slider__input"
87-
min=min.to_string() max=max.to_string() step=step.to_string()
88-
oninput=onchange.reform(|data: InputData| data.value.parse().unwrap())
89-
value=value.to_string()
87+
min={min.to_string()} max={max.to_string()} step={step.to_string()}
88+
oninput={onchange.reform(|data: InputData| data.value.parse().unwrap())}
89+
value={value.to_string()}
9090
/>
9191
<span class="slider__value">{ display_value }</span>
9292
</div>

examples/counter/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ impl Component for Model {
4545
<div>
4646
<div class="panel">
4747
// A button to send the Increment message
48-
<button class="button" onclick=self.link.callback(|_| Msg::Increment)>
48+
<button class="button" onclick={self.link.callback(|_| Msg::Increment)}>
4949
{ "+1" }
5050
</button>
5151

5252
// A button to send the Decrement message
53-
<button onclick=self.link.callback(|_| Msg::Decrement)>
53+
<button onclick={self.link.callback(|_| Msg::Decrement)}>
5454
{ "-1" }
5555
</button>
5656

5757
// A button to send two Increment messages
58-
<button onclick=self.link.batch_callback(|_| vec![Msg::Increment, Msg::Increment])>
58+
<button onclick={self.link.batch_callback(|_| vec![Msg::Increment, Msg::Increment])}>
5959
{ "+1, +1" }
6060
</button>
6161

examples/crm/src/add_client.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,32 @@ impl Component for AddClientForm {
7676
<>
7777
<div class="names">
7878
<input
79-
class=classes!("new-client", "firstname")
79+
class={classes!("new-client", "firstname")}
8080
placeholder="First name"
81-
value=client.first_name.clone()
82-
oninput=link.callback(|e: InputData| Msg::UpdateFirstName(e.value))
81+
value={client.first_name.clone()}
82+
oninput={link.callback(|e: InputData| Msg::UpdateFirstName(e.value))}
8383
/>
8484
<input
85-
class=classes!("new-client", "lastname")
85+
class={classes!("new-client", "lastname")}
8686
placeholder="Last name"
87-
value=client.last_name.clone()
88-
oninput=link.callback(|e: InputData| Msg::UpdateLastName(e.value))
87+
value={client.last_name.clone()}
88+
oninput={link.callback(|e: InputData| Msg::UpdateLastName(e.value))}
8989
/>
9090
<textarea
91-
class=classes!("new-client", "description")
91+
class={classes!("new-client", "description")}
9292
placeholder="Description"
93-
value=client.description.clone()
94-
oninput=link.callback(|e: InputData| Msg::UpdateDescription(e.value))
93+
value={client.description.clone()}
94+
oninput={link.callback(|e: InputData| Msg::UpdateDescription(e.value))}
9595
/>
9696
</div>
9797

9898
<button
99-
disabled=client.first_name.is_empty() || client.last_name.is_empty()
100-
onclick=link.callback(|_| Msg::Add)
99+
disabled={client.first_name.is_empty() || client.last_name.is_empty()}
100+
onclick={link.callback(|_| Msg::Add)}
101101
>
102102
{ "Add New" }
103103
</button>
104-
<button onclick=link.callback(|_| Msg::Abort)>
104+
<button onclick={link.callback(|_| Msg::Abort)}>
105105
{ "Go Back" }
106106
</button>
107107
</>

examples/crm/src/main.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@ impl Component for Model {
9797
<div class="clients">
9898
{ for self.clients.iter().map(Client::render) }
9999
</div>
100-
<button onclick=self.link.callback(|_| Msg::SwitchTo(Scene::NewClientForm))>{ "Add New" }</button>
101-
<button onclick=self.link.callback(|_| Msg::SwitchTo(Scene::Settings))>{ "Settings" }</button>
100+
<button onclick={self.link.callback(|_| Msg::SwitchTo(Scene::NewClientForm))}>{ "Add New" }</button>
101+
<button onclick={self.link.callback(|_| Msg::SwitchTo(Scene::Settings))}>{ "Settings" }</button>
102102
</div>
103103
},
104104
Scene::NewClientForm => html! {
105105
<div class="crm">
106106
<h1>{"Add a new client"}</h1>
107-
<AddClientForm on_add=self.link.callback(Msg::AddClient) on_abort=self.link.callback(|_| Msg::SwitchTo(Scene::ClientsList)) />
107+
<AddClientForm on_add={self.link.callback(Msg::AddClient)} on_abort={self.link.callback(|_| Msg::SwitchTo(Scene::ClientsList))} />
108108
</div>
109109
},
110110
Scene::Settings => html! {
111111
<div>
112112
<h1>{"Settings"}</h1>
113-
<button onclick=self.link.callback(|_| Msg::ClearClients)>{ "Remove all clients" }</button>
114-
<button onclick=self.link.callback(|_| Msg::SwitchTo(Scene::ClientsList))>{ "Go Back" }</button>
113+
<button onclick={self.link.callback(|_| Msg::ClearClients)}>{ "Remove all clients" }</button>
114+
<button onclick={self.link.callback(|_| Msg::SwitchTo(Scene::ClientsList))}>{ "Go Back" }</button>
115115
</div>
116116
},
117117
}

examples/dyn_create_destroy_apps/src/counter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl Component for CounterModel {
5858
</p>
5959

6060
// Add button to send a destroy command to the parent app
61-
<button class="destroy" onclick=Callback::from(move |_| destroy_callback.emit(()))>
61+
<button class="destroy" onclick={Callback::from(move |_| destroy_callback.emit(()))}>
6262
{ "Destroy this app" }
6363
</button>
6464
</>

examples/dyn_create_destroy_apps/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ impl Component for Model {
9898
// Create button to create a new app
9999
<button
100100
class="create"
101-
onclick=self.link.callback(|_| Msg::SpawnCounterAppInstance)
101+
onclick={self.link.callback(|_| Msg::SpawnCounterAppInstance)}
102102
>
103103
{ "Spawn new CounterModel app" }
104104
</button>
105105
</div>
106106
// Create a container for all the app instances
107-
<div ref=self.apps_container_ref.clone()>
107+
<div ref={self.apps_container_ref.clone()}>
108108
</div>
109109
</>
110110
}

examples/file_upload/src/main.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Component for Model {
8787
<div>
8888
<div>
8989
<p>{ "Choose a file to upload to see the uploaded bytes" }</p>
90-
<input type="file" multiple=true onchange=self.link.callback(move |value| {
90+
<input type="file" multiple=true onchange={self.link.callback(move |value| {
9191
let mut result = Vec::new();
9292
if let ChangeData::Files(files) = value {
9393
let files = js_sys::try_iter(&files)
@@ -98,12 +98,12 @@ impl Component for Model {
9898
result.extend(files);
9999
}
100100
Msg::Files(result, flag)
101-
})
101+
})}
102102
/>
103103
</div>
104104
<div>
105105
<label>{ "Read bytes" }</label>
106-
<input type="checkbox" checked=flag onclick=self.link.callback(|_| Msg::ToggleReadBytes) />
106+
<input type="checkbox" checked={flag} onclick={self.link.callback(|_| Msg::ToggleReadBytes)} />
107107
</div>
108108
<ul>
109109
{ for self.files.iter().map(|f| Self::view_file(f)) }

examples/futures/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ impl Component for Model {
118118
match &self.markdown {
119119
FetchState::NotFetching => html! {
120120
<>
121-
<button onclick=self.link.callback(|_| Msg::GetMarkdown)>
121+
<button onclick={self.link.callback(|_| Msg::GetMarkdown)}>
122122
{ "Get Markdown" }
123123
</button>
124-
<button onclick=self.link.callback(|_| Msg::GetError)>
124+
<button onclick={self.link.callback(|_| Msg::GetError)}>
125125
{ "Get using incorrect URL" }
126126
</button>
127127
</>

examples/game_of_life/src/main.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ impl Model {
9595
}
9696
};
9797
html! {
98-
<div key=idx class=classes!("game-cellule", cellule_status)
99-
onclick=self.link.callback(move |_| Msg::ToggleCellule(idx))>
98+
<div key={idx} class={classes!("game-cellule", cellule_status)}
99+
onclick={self.link.callback(move |_| Msg::ToggleCellule(idx))}>
100100
</div>
101101
}
102102
}
@@ -180,7 +180,7 @@ impl Component for Model {
180180
.enumerate()
181181
.map(|(x, cell)| self.view_cellule(idx_offset + x, cell));
182182
html! {
183-
<div key=y class="game-row">
183+
<div key={y} class="game-row">
184184
{ for cells }
185185
</div>
186186
}
@@ -198,11 +198,11 @@ impl Component for Model {
198198
{ for cell_rows }
199199
</div>
200200
<div class="game-buttons">
201-
<button class="game-button" onclick=self.link.callback(|_| Msg::Random)>{ "Random" }</button>
202-
<button class="game-button" onclick=self.link.callback(|_| Msg::Step)>{ "Step" }</button>
203-
<button class="game-button" onclick=self.link.callback(|_| Msg::Start)>{ "Start" }</button>
204-
<button class="game-button" onclick=self.link.callback(|_| Msg::Stop)>{ "Stop" }</button>
205-
<button class="game-button" onclick=self.link.callback(|_| Msg::Reset)>{ "Reset" }</button>
201+
<button class="game-button" onclick={self.link.callback(|_| Msg::Random)}>{ "Random" }</button>
202+
<button class="game-button" onclick={self.link.callback(|_| Msg::Step)}>{ "Step" }</button>
203+
<button class="game-button" onclick={self.link.callback(|_| Msg::Start)}>{ "Start" }</button>
204+
<button class="game-button" onclick={self.link.callback(|_| Msg::Stop)}>{ "Stop" }</button>
205+
<button class="game-button" onclick={self.link.callback(|_| Msg::Reset)}>{ "Reset" }</button>
206206
</div>
207207
</section>
208208
</section>

examples/js_callback/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ impl Component for Model {
5757
<>
5858
<textarea
5959
class="code-block"
60-
oninput=self.link.callback(|input: InputData| Msg::Payload(input.value))
61-
value=self.payload.clone()
60+
oninput={self.link.callback(|input: InputData| Msg::Payload(input.value))}
61+
value={self.payload.clone()}
6262
/>
63-
<button onclick=self.link.callback(|_| Msg::Payload(bindings::get_payload()))>
63+
<button onclick={self.link.callback(|_| Msg::Payload(bindings::get_payload()))}>
6464
{ "Get the payload!" }
6565
</button>
66-
<button onclick=self.link.callback(|_| Msg::AsyncPayload) >
66+
<button onclick={self.link.callback(|_| Msg::AsyncPayload)} >
6767
{ "Get the payload later!" }
6868
</button>
6969
<p class="code-block">

0 commit comments

Comments
 (0)