Skip to content

Commit 1756151

Browse files
committed
fix: clippy, format
1 parent 9d437ac commit 1756151

File tree

8 files changed

+59
-40
lines changed

8 files changed

+59
-40
lines changed

examples/app_builder/src/lib.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
use seed::{*, prelude::*};
1+
use seed::{prelude::*, *};
22
use web_sys;
33

44
// ------ ------
55
// Model
66
// ------ ------
77

8+
#[derive(Default)]
89
struct Model {
910
clicks: u32,
1011
}
@@ -27,11 +28,11 @@ fn update(msg: Msg, model: &mut Model, orders: &mut impl Orders<Msg, GMsg>) {
2728
Msg::UrlChanged(url) => {
2829
log!(url);
2930
orders.skip();
30-
},
31+
}
3132
Msg::KeyPressed(event) => {
3233
log!(event.key());
3334
orders.skip();
34-
},
35+
}
3536
Msg::SayHello => {
3637
orders.send_g_msg(GMsg::SayHello);
3738
}
@@ -48,10 +49,7 @@ fn view(model: &Model) -> impl View<Msg> {
4849
format!("Clicked: {}", model.clicks),
4950
simple_ev(Ev::Click, Msg::Clicked),
5051
],
51-
button![
52-
"Say hello",
53-
simple_ev(Ev::Click, Msg::SayHello),
54-
]
52+
button!["Say hello", simple_ev(Ev::Click, Msg::SayHello),],
5553
]
5654
}
5755

@@ -68,15 +66,14 @@ fn routes(url: Url) -> Option<Msg> {
6866
// ------ ------
6967

7068
fn window_events(_model: &Model) -> Vec<Listener<Msg>> {
71-
vec![
72-
keyboard_ev(Ev::KeyDown, Msg::KeyPressed)
73-
]
69+
vec![keyboard_ev(Ev::KeyDown, Msg::KeyPressed)]
7470
}
7571

7672
// ------ ------
7773
// Sink
7874
// ------ ------
7975

76+
#[derive(Clone, Copy)]
8077
enum GMsg {
8178
SayHello,
8279
}
@@ -91,7 +88,7 @@ fn sink(g_msg: GMsg, _model: &mut Model, _orders: &mut impl Orders<Msg, GMsg>) {
9188
// Before Mount
9289
// ------ ------
9390

94-
fn before_mount(_url: Url) -> BeforeMount {
91+
fn before_mount(_: Url) -> BeforeMount {
9592
BeforeMount::new()
9693
.mount_point("main")
9794
.mount_type(MountType::Takeover)
@@ -101,9 +98,8 @@ fn before_mount(_url: Url) -> BeforeMount {
10198
// After Mount
10299
// ------ ------
103100

104-
fn after_mount(_url: Url, _orders: &mut impl Orders<Msg, GMsg>) -> AfterMount<Model> {
105-
AfterMount::new(Model { clicks: 0 })
106-
.url_handling(UrlHandling::None)
101+
fn after_mount(_: Url, _orders: &mut impl Orders<Msg, GMsg>) -> AfterMount<Model> {
102+
AfterMount::new(Model { clicks: 0 }).url_handling(UrlHandling::None)
107103
}
108104

109105
// ------ ------

examples/drop/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ struct Model {
1111
drop_zone_content: Vec<Node<Msg>>,
1212
}
1313

14+
// After Mount
15+
16+
fn after_mount(_: Url, _: &mut impl Orders<Msg>) -> AfterMount<Model> {
17+
AfterMount::new(Model {
18+
drop_zone_active: false,
19+
drop_zone_content: vec![div!["Drop files here"]],
20+
})
21+
}
22+
1423
// Update
1524

1625
#[derive(Clone, Debug)]
@@ -109,9 +118,6 @@ fn view(model: &Model) -> impl View<Msg> {
109118
#[wasm_bindgen(start)]
110119
pub fn start() {
111120
seed::App::builder(update, view)
112-
.after_mount(AfterMount::new(Model {
113-
drop_zone_active: false,
114-
drop_zone_content: vec![div!["Drop files here"]],
115-
}))
121+
.after_mount(after_mount)
116122
.build_and_start();
117123
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub mod prelude {
8989
},
9090
events::{
9191
input_ev, keyboard_ev, mouse_ev, pointer_ev, raw_ev, simple_ev, trigger_update_handler,
92-
Ev, Listener
92+
Ev, Listener,
9393
},
9494
orders::Orders,
9595
routing::Url,

src/orders.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::dom_types::{MessageMapper, View};
2-
use crate::vdom::{App, Effect, RenderTimestampDelta, ShouldRender};
2+
use crate::vdom::{App, Effect, RenderTimestampDelta, ShouldRender, UndefinedGMsg};
33
use futures::Future;
44
use std::{collections::VecDeque, convert::identity, rc::Rc};
55

66
// ------ Orders ------
77

8-
pub trait Orders<Ms: 'static, GMs = ()> {
8+
pub trait Orders<Ms: 'static, GMs = UndefinedGMsg> {
99
type AppMs: 'static;
1010
type Mdl: 'static;
1111
type ElC: View<Self::AppMs> + 'static;
@@ -96,7 +96,7 @@ pub trait Orders<Ms: 'static, GMs = ()> {
9696
// ------ OrdersContainer ------
9797

9898
#[allow(clippy::module_name_repetitions)]
99-
pub struct OrdersContainer<Ms: 'static, Mdl: 'static, ElC: View<Ms>, GMs = ()> {
99+
pub struct OrdersContainer<Ms: 'static, Mdl: 'static, ElC: View<Ms>, GMs = UndefinedGMsg> {
100100
pub(crate) should_render: ShouldRender,
101101
pub(crate) effects: VecDeque<Effect<Ms, GMs>>,
102102
app: App<Ms, Mdl, ElC, GMs>,
@@ -200,7 +200,14 @@ impl<Ms: 'static, Mdl, ElC: View<Ms> + 'static, GMs> Orders<Ms, GMs>
200200
// ------ OrdersProxy ------
201201

202202
#[allow(clippy::module_name_repetitions)]
203-
pub struct OrdersProxy<'a, Ms, AppMs: 'static, Mdl: 'static, ElC: View<AppMs>, GMs: 'static = ()> {
203+
pub struct OrdersProxy<
204+
'a,
205+
Ms,
206+
AppMs: 'static,
207+
Mdl: 'static,
208+
ElC: View<AppMs>,
209+
GMs: 'static = UndefinedGMsg,
210+
> {
204211
orders_container: &'a mut OrdersContainer<AppMs, Mdl, ElC, GMs>,
205212
f: Rc<dyn Fn(Ms) -> AppMs>,
206213
}

src/vdom.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use alias::*;
2020
pub mod builder;
2121
pub use builder::{
2222
AfterMount, BeforeMount, Builder as AppBuilder, Init, InitFn, MountPoint, MountType,
23-
UrlHandling, UndefinedInitAPI, UndefinedMountPoint
23+
UndefinedInitAPI, UndefinedMountPoint, UrlHandling,
2424
};
2525

2626
use crate::{
@@ -177,8 +177,13 @@ impl<Ms: 'static, Mdl: 'static, ElC: View<Ms>, GMs> ::std::fmt::Debug for App<Ms
177177
}
178178

179179
#[deprecated(since = "0.5.0", note = "Part of the old Init API.")]
180-
type InitAppBuilder<Ms, Mdl, ElC, GMs> =
181-
AppBuilder<Ms, Mdl, ElC, GMs, builder::MountPointInitInitAPI<UndefinedMountPoint, InitFn<Ms, Mdl, ElC, GMs>>>;
180+
type InitAppBuilder<Ms, Mdl, ElC, GMs> = AppBuilder<
181+
Ms,
182+
Mdl,
183+
ElC,
184+
GMs,
185+
builder::MountPointInitInitAPI<UndefinedMountPoint, InitFn<Ms, Mdl, ElC, GMs>>,
186+
>;
182187

183188
/// We use a struct instead of series of functions, in order to avoid passing
184189
/// repetitive sequences of parameters.

src/vdom/builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<
175175
}
176176
// TODO Remove when removing the other `InitAPI`s.
177177
impl<Ms: 'static, Mdl: 'static + Default, ElC: 'static + View<Ms>, GMs: 'static>
178-
InitAPI<Ms, Mdl, ElC, GMs> for UndefinedAfterMount
178+
InitAPI<Ms, Mdl, ElC, GMs> for UndefinedInitAPI
179179
{
180180
type Builder = Builder<Ms, Mdl, ElC, GMs, Self>;
181181
fn build(builder: Self::Builder) -> App<Ms, Mdl, ElC, GMs> {
@@ -461,7 +461,7 @@ impl<
461461

462462
pub fn after_mount<NewIAM: 'static + IntoAfterMount<Ms, Mdl, ElC, GMs>>(
463463
self,
464-
new_after_mount: NewIAM,
464+
after_mount: NewIAM,
465465
) -> Builder<Ms, Mdl, ElC, GMs, BeforeAfterInitAPI<NewIAM>> {
466466
Builder {
467467
update: self.update,
@@ -471,7 +471,7 @@ impl<
471471
window_events: self.window_events,
472472
sink: self.sink,
473473

474-
init_api: self.init_api.after_mount(new_after_mount),
474+
init_api: self.init_api.after_mount(after_mount),
475475
}
476476
}
477477

@@ -482,8 +482,8 @@ impl<
482482
}
483483

484484
/// Registers a function which decides how window events will be handled.
485-
pub fn window_events(mut self, evts: WindowEvents<Ms, Mdl>) -> Self {
486-
self.window_events = Some(evts);
485+
pub fn window_events(mut self, window_events: WindowEvents<Ms, Mdl>) -> Self {
486+
self.window_events = Some(window_events);
487487
self
488488
}
489489

src/vdom/builder/after_mount.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{dom_types::View, orders::OrdersContainer, routing::Url};
22

3+
#[allow(clippy::module_name_repetitions)]
34
pub struct UndefinedAfterMount;
45

56
// ------ UrlHandling ------
@@ -76,7 +77,9 @@ where
7677
}
7778
}
7879

79-
impl<Ms: 'static, Mdl: Default, ElC: View<Ms>, GMs> IntoAfterMount<Ms, Mdl, ElC, GMs> for UndefinedAfterMount {
80+
impl<Ms: 'static, Mdl: Default, ElC: View<Ms>, GMs> IntoAfterMount<Ms, Mdl, ElC, GMs>
81+
for UndefinedAfterMount
82+
{
8083
fn into_after_mount(
8184
self: Box<Self>,
8285
_: Url,

src/vdom/builder/before_mount.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ pub trait MountPoint {
1111
impl MountPoint for &str {
1212
fn element_getter(self) -> Box<dyn FnOnce() -> Element> {
1313
let id = self.to_owned();
14-
Box::new(move || util::document().get_element_by_id(&id).unwrap_or_else(|| {
15-
panic!(
16-
"Can't find element with id={:?} - app cannot be mounted!\n\
17-
(Id defaults to \"app\", or can be set with the .mount() method)",
18-
id
19-
)
20-
}))
14+
Box::new(move || {
15+
util::document().get_element_by_id(&id).unwrap_or_else(|| {
16+
panic!(
17+
"Can't find element with id={:?} - app cannot be mounted!\n\
18+
(Id defaults to \"app\", or can be set with the .mount() method)",
19+
id
20+
)
21+
})
22+
})
2123
}
2224
}
2325

@@ -74,7 +76,7 @@ impl BeforeMount {
7476
self
7577
}
7678

77-
pub fn mount_type(mut self, mount_type: MountType) -> Self {
79+
pub const fn mount_type(mut self, mount_type: MountType) -> Self {
7880
self.mount_type = mount_type;
7981
self
8082
}

0 commit comments

Comments
 (0)