mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
Fix clippy lints from 1.54.0 (#1976)
* Fix clippy lints from 1.54.0 * Format fixed code
This commit is contained in:
parent
f94487364f
commit
c9deba05f1
@ -127,7 +127,7 @@ impl Component for Model {
|
||||
</>
|
||||
},
|
||||
FetchState::Fetching => html! { "Fetching" },
|
||||
FetchState::Success(data) => html! { markdown::render_markdown(&data) },
|
||||
FetchState::Success(data) => html! { markdown::render_markdown(data) },
|
||||
FetchState::Failed(err) => html! { err },
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,10 +5,10 @@ use yew_agent::AgentLink;
|
||||
pub type PostId = u32;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Request {
|
||||
CreatePost(String),
|
||||
UpdatePost(PostId, String),
|
||||
RemovePost(PostId),
|
||||
pub enum PostRequest {
|
||||
Create(String),
|
||||
Update(PostId, String),
|
||||
Remove(PostId),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -25,7 +25,7 @@ pub struct PostStore {
|
||||
|
||||
impl Store for PostStore {
|
||||
type Action = Action;
|
||||
type Input = Request;
|
||||
type Input = PostRequest;
|
||||
|
||||
fn new() -> Self {
|
||||
let mut posts = HashMap::new();
|
||||
@ -42,13 +42,13 @@ impl Store for PostStore {
|
||||
|
||||
fn handle_input(&self, link: AgentLink<StoreWrapper<Self>>, msg: Self::Input) {
|
||||
match msg {
|
||||
Request::CreatePost(text) => {
|
||||
PostRequest::Create(text) => {
|
||||
link.send_message(Action::SetPost(None, text));
|
||||
}
|
||||
Request::UpdatePost(id, text) => {
|
||||
PostRequest::Update(id, text) => {
|
||||
link.send_message(Action::SetPost(Some(id), text));
|
||||
}
|
||||
Request::RemovePost(id) => {
|
||||
PostRequest::Remove(id) => {
|
||||
link.send_message(Action::RemovePost(id));
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ mod agents;
|
||||
mod post;
|
||||
mod text_input;
|
||||
|
||||
use agents::posts::{PostId, PostStore, Request};
|
||||
use agents::posts::{PostId, PostRequest, PostStore};
|
||||
use post::Post;
|
||||
use text_input::TextInput;
|
||||
use weblog::console_log;
|
||||
@ -37,7 +37,7 @@ impl Component for Model {
|
||||
fn update(&mut self, msg: Self::Message) -> ShouldRender {
|
||||
match msg {
|
||||
Msg::CreatePost(text) => {
|
||||
self.post_store.send(Request::CreatePost(text));
|
||||
self.post_store.send(PostRequest::Create(text));
|
||||
false
|
||||
}
|
||||
Msg::PostStoreMsg(state) => {
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use crate::agents::posts::{PostId, PostStore, Request};
|
||||
use crate::agents::posts::{PostId, PostRequest, PostStore};
|
||||
use crate::text_input::TextInput;
|
||||
use yew::prelude::*;
|
||||
use yew::utils::NeqAssign;
|
||||
@ -8,7 +8,7 @@ use yew_agent::Bridge;
|
||||
pub enum Msg {
|
||||
UpdateText(String),
|
||||
Delete,
|
||||
PostStoreMsg(ReadOnly<PostStore>),
|
||||
PostStore(ReadOnly<PostStore>),
|
||||
}
|
||||
|
||||
#[derive(Properties, Clone, PartialEq)]
|
||||
@ -28,7 +28,7 @@ impl Component for Post {
|
||||
type Properties = Props;
|
||||
|
||||
fn create(props: Self::Properties, link: ComponentLink<Self>) -> Self {
|
||||
let callback = link.callback(Msg::PostStoreMsg);
|
||||
let callback = link.callback(Msg::PostStore);
|
||||
Self {
|
||||
link,
|
||||
id: props.id,
|
||||
@ -40,14 +40,14 @@ impl Component for Post {
|
||||
fn update(&mut self, msg: Self::Message) -> ShouldRender {
|
||||
match msg {
|
||||
Msg::UpdateText(text) => {
|
||||
self.post_store.send(Request::UpdatePost(self.id, text));
|
||||
self.post_store.send(PostRequest::Update(self.id, text));
|
||||
false
|
||||
}
|
||||
Msg::Delete => {
|
||||
self.post_store.send(Request::RemovePost(self.id));
|
||||
self.post_store.send(PostRequest::Remove(self.id));
|
||||
false
|
||||
}
|
||||
Msg::PostStoreMsg(state) => {
|
||||
Msg::PostStore(state) => {
|
||||
let state = state.borrow();
|
||||
|
||||
// Only update if the post changed.
|
||||
|
||||
@ -220,7 +220,7 @@ impl Model {
|
||||
<label ondblclick={self.link.callback(move |_| Msg::ToggleEdit(idx))}>{ &entry.description }</label>
|
||||
<button class="destroy" onclick={self.link.callback(move |_| Msg::Remove(idx))} />
|
||||
</div>
|
||||
{ self.view_entry_edit_input((idx, &entry)) }
|
||||
{ self.view_entry_edit_input((idx, entry)) }
|
||||
</li>
|
||||
}
|
||||
}
|
||||
|
||||
@ -103,11 +103,11 @@ impl Model {
|
||||
gl.buffer_data_with_array_buffer_view(GL::ARRAY_BUFFER, &verts, GL::STATIC_DRAW);
|
||||
|
||||
let vert_shader = gl.create_shader(GL::VERTEX_SHADER).unwrap();
|
||||
gl.shader_source(&vert_shader, &vert_code);
|
||||
gl.shader_source(&vert_shader, vert_code);
|
||||
gl.compile_shader(&vert_shader);
|
||||
|
||||
let frag_shader = gl.create_shader(GL::FRAGMENT_SHADER).unwrap();
|
||||
gl.shader_source(&frag_shader, &frag_code);
|
||||
gl.shader_source(&frag_shader, frag_code);
|
||||
gl.compile_shader(&frag_shader);
|
||||
|
||||
let shader_program = gl.create_program().unwrap();
|
||||
|
||||
@ -34,7 +34,7 @@ impl<T: Serialize + for<'de> Deserialize<'de>> Packed for T {
|
||||
}
|
||||
|
||||
fn unpack(data: &[u8]) -> Self {
|
||||
bincode::deserialize(&data).expect("can't deserialize an agent message")
|
||||
bincode::deserialize(data).expect("can't deserialize an agent message")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -41,13 +41,13 @@ impl ToTokens for PropsBuilder<'_> {
|
||||
|
||||
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();
|
||||
let turbofish_generics = ty_generics.as_turbofish();
|
||||
let generic_args = to_arguments(&generics, build_step.clone());
|
||||
let generic_args = to_arguments(generics, build_step.clone());
|
||||
|
||||
// Each builder step implements the `BuilderStep` trait and `step_generics` is used to
|
||||
// enforce that.
|
||||
let step_generic_param = Ident::new("YEW_PROPS_BUILDER_STEP", Span::call_site());
|
||||
let step_generics =
|
||||
with_param_bounds(&generics, step_generic_param.clone(), (*step_trait).clone());
|
||||
with_param_bounds(generics, step_generic_param.clone(), (*step_trait).clone());
|
||||
|
||||
let builder = quote! {
|
||||
#(
|
||||
|
||||
@ -61,13 +61,13 @@ impl ToTokens for DerivePropsInput {
|
||||
|
||||
// The wrapper is a new struct which wraps required props in `Option`
|
||||
let wrapper_name = Ident::new(&format!("{}Wrapper", props_name), Span::call_site());
|
||||
let wrapper = PropsWrapper::new(&wrapper_name, &generics, &self.prop_fields);
|
||||
let wrapper = PropsWrapper::new(&wrapper_name, generics, &self.prop_fields);
|
||||
tokens.extend(wrapper.into_token_stream());
|
||||
|
||||
// The builder will only build if all required props have been set
|
||||
let builder_name = Ident::new(&format!("{}Builder", props_name), Span::call_site());
|
||||
let builder_step = Ident::new(&format!("{}BuilderStep", props_name), Span::call_site());
|
||||
let builder = PropsBuilder::new(&builder_name, &builder_step, &self, &wrapper_name);
|
||||
let builder = PropsBuilder::new(&builder_name, &builder_step, self, &wrapper_name);
|
||||
let builder_generic_args = builder.first_step_generic_args();
|
||||
tokens.extend(builder.into_token_stream());
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ pub fn build_router<R: Routable>() -> Router {
|
||||
router.add(route, path.to_string());
|
||||
}
|
||||
_ => {
|
||||
router.add(&path, path.to_string());
|
||||
router.add(path, path.to_string());
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
@ -61,7 +61,7 @@ where
|
||||
T: for<'de> Deserialize<'de>,
|
||||
{
|
||||
let query = yew::utils::document().location().unwrap().search().unwrap();
|
||||
serde_urlencoded::from_str(query.strip_prefix("?").unwrap_or(""))
|
||||
serde_urlencoded::from_str(query.strip_prefix('?').unwrap_or(""))
|
||||
}
|
||||
|
||||
pub fn current_route<R: Routable>() -> Option<R> {
|
||||
|
||||
@ -2,7 +2,7 @@ use std::cell::RefCell;
|
||||
use wasm_bindgen::JsCast;
|
||||
|
||||
pub(crate) fn strip_slash_suffix(path: &str) -> &str {
|
||||
path.strip_suffix("/").unwrap_or(&path)
|
||||
path.strip_suffix('/').unwrap_or(path)
|
||||
}
|
||||
|
||||
static BASE_URL_LOADED: std::sync::Once = std::sync::Once::new();
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
#[macro_use]
|
||||
macro_rules! impl_action {
|
||||
($($action:ident(name: $name:literal, event: $type:ident) -> $ret:ty => $convert:expr)*) => {$(
|
||||
/// An abstract implementation of a listener.
|
||||
|
||||
@ -314,8 +314,7 @@ impl Attributes {
|
||||
}
|
||||
|
||||
fn set_attribute(el: &Element, key: &str, value: &str) {
|
||||
el.set_attribute(&key, &value)
|
||||
.expect("invalid attribute key")
|
||||
el.set_attribute(key, value).expect("invalid attribute key")
|
||||
}
|
||||
}
|
||||
|
||||
@ -327,7 +326,7 @@ impl Apply for Attributes {
|
||||
Self::Vec(v) => {
|
||||
for attr in v.iter() {
|
||||
if let Some(v) = &attr.1 {
|
||||
Self::set_attribute(el, &attr.0, v)
|
||||
Self::set_attribute(el, attr.0, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -346,7 +345,7 @@ impl Apply for Attributes {
|
||||
Self::set_attribute(el, key, value);
|
||||
}
|
||||
Patch::Remove(key) => {
|
||||
el.remove_attribute(&key)
|
||||
el.remove_attribute(key)
|
||||
.expect("could not remove attribute");
|
||||
}
|
||||
}
|
||||
@ -425,7 +424,7 @@ pub(crate) trait VDiff {
|
||||
pub(crate) fn insert_node(node: &Node, parent: &Element, next_sibling: Option<&Node>) {
|
||||
match next_sibling {
|
||||
Some(next_sibling) => parent
|
||||
.insert_before(&node, Some(next_sibling))
|
||||
.insert_before(node, Some(next_sibling))
|
||||
.expect("failed to insert tag before next sibling"),
|
||||
None => parent.append_child(node).expect("failed to append child"),
|
||||
};
|
||||
@ -606,17 +605,17 @@ mod benchmarks {
|
||||
const TIME_LIMIT: f64 = 2.0;
|
||||
|
||||
let vv = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_vec, &old_vec), |(new, old)| {
|
||||
format!("{:?}", Attributes::diff(&new, &old))
|
||||
format!("{:?}", Attributes::diff(new, old))
|
||||
});
|
||||
let mm = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_map, &old_map), |(new, old)| {
|
||||
format!("{:?}", Attributes::diff(&new, &old))
|
||||
format!("{:?}", Attributes::diff(new, old))
|
||||
});
|
||||
|
||||
let vm = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_vec, &old_map), |(new, old)| {
|
||||
format!("{:?}", Attributes::diff(&new, &old))
|
||||
format!("{:?}", Attributes::diff(new, old))
|
||||
});
|
||||
let mv = easybench_wasm::bench_env_limit(TIME_LIMIT, (&new_map, &old_vec), |(new, old)| {
|
||||
format!("{:?}", Attributes::diff(&new, &old))
|
||||
format!("{:?}", Attributes::diff(new, old))
|
||||
});
|
||||
|
||||
wasm_bindgen_test::console_log!(
|
||||
|
||||
@ -422,7 +422,7 @@ mod tests {
|
||||
// clear parent
|
||||
parent.set_inner_html("");
|
||||
|
||||
node.apply(&scope, &parent, NodeRef::default(), None);
|
||||
node.apply(scope, parent, NodeRef::default(), None);
|
||||
parent.inner_html()
|
||||
}
|
||||
|
||||
|
||||
@ -165,7 +165,7 @@ impl Apply for Listeners {
|
||||
*self = Self::Registered(
|
||||
std::mem::take(v)
|
||||
.into_iter()
|
||||
.map(|l| l.attach(&el))
|
||||
.map(|l| l.attach(el))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user