From b046f6b5bc28fa00222c125f5b3529c3c840cf19 Mon Sep 17 00:00:00 2001 From: Mark Wainwright Date: Tue, 14 Mar 2023 10:56:57 +0000 Subject: [PATCH] fix formatting --- crates/yewdux-input/src/lib.rs | 2 +- crates/yewdux-macros/src/store.rs | 25 +++++++++++++------------ crates/yewdux/src/listener.rs | 20 +++++++++----------- examples/persistent/src/main.rs | 8 +++++--- examples/todomvc/src/state.rs | 5 +---- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/crates/yewdux-input/src/lib.rs b/crates/yewdux-input/src/lib.rs index ceec102..2d8e134 100644 --- a/crates/yewdux-input/src/lib.rs +++ b/crates/yewdux-input/src/lib.rs @@ -1,10 +1,10 @@ use std::{rc::Rc, str::FromStr}; +use serde::{Deserialize, Serialize}; use wasm_bindgen::JsCast; use web_sys::{HtmlInputElement, HtmlTextAreaElement}; use yew::prelude::*; use yewdux::prelude::*; -use serde::{Deserialize, Serialize}; pub enum InputElement { Input(HtmlInputElement), diff --git a/crates/yewdux-macros/src/store.rs b/crates/yewdux-macros/src/store.rs index 5bb8a50..332b196 100644 --- a/crates/yewdux-macros/src/store.rs +++ b/crates/yewdux-macros/src/store.rs @@ -1,4 +1,4 @@ -use darling::{FromDeriveInput, util::PathList}; +use darling::{util::PathList, FromDeriveInput}; use proc_macro2::TokenStream; use quote::quote; use syn::DeriveInput; @@ -8,7 +8,7 @@ use syn::DeriveInput; struct Opts { storage: Option, storage_tab_sync: bool, - listener: PathList + listener: PathList, } pub(crate) fn derive(input: DeriveInput) -> TokenStream { @@ -16,14 +16,17 @@ pub(crate) fn derive(input: DeriveInput) -> TokenStream { let ident = input.ident; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - - let extra_listeners : Vec<_> = opts.listener.iter().map(|path| - quote!{ - ::yewdux::listener::init_listener( - #path - ); - } - ).collect(); + let extra_listeners: Vec<_> = opts + .listener + .iter() + .map(|path| { + quote! { + ::yewdux::listener::init_listener( + #path + ); + } + }) + .collect(); let impl_ = match opts.storage { Some(storage) => { @@ -46,8 +49,6 @@ pub(crate) fn derive(input: DeriveInput) -> TokenStream { quote!() }; - - quote! { #[cfg(target_arch = "wasm32")] fn new() -> Self { diff --git a/crates/yewdux/src/listener.rs b/crates/yewdux/src/listener.rs index 7bbadac..c3c65ac 100644 --- a/crates/yewdux/src/listener.rs +++ b/crates/yewdux/src/listener.rs @@ -9,16 +9,16 @@ pub trait Listener: 'static { fn on_change(&mut self, state: Rc); } -struct ListenerStore(Option>); - impl Store for Mrc> { - fn new() -> Self { - ListenerStore(None).into() - } +struct ListenerStore(Option>); +impl Store for Mrc> { + fn new() -> Self { + ListenerStore(None).into() + } - fn should_notify(&self, other: &Self) -> bool { - self != other - } + fn should_notify(&self, other: &Self) -> bool { + self != other } +} /// Initiate a [Listener]. If this listener has already been initiated, it is dropped and replaced /// with the new one. @@ -28,9 +28,7 @@ pub fn init_listener(listener: L) { dispatch::subscribe_silent(move |state| listener.borrow_mut().on_change(state)) }; - dispatch::reduce_mut(|state: &mut Mrc>| { - state.borrow_mut().0 = Some(id) - }); + dispatch::reduce_mut(|state: &mut Mrc>| state.borrow_mut().0 = Some(id)); } #[cfg(test)] diff --git a/examples/persistent/src/main.rs b/examples/persistent/src/main.rs index 82b95df..be7c227 100644 --- a/examples/persistent/src/main.rs +++ b/examples/persistent/src/main.rs @@ -1,7 +1,10 @@ use std::rc::Rc; use yew::prelude::*; -use yewdux::{prelude::*, log::{log, Level}}; +use yewdux::{ + log::{log, Level}, + prelude::*, +}; use serde::{Deserialize, Serialize}; @@ -29,7 +32,6 @@ fn main() { yew::Renderer::::new().render(); } - struct LogListener; impl Listener for LogListener { type Store = State; @@ -37,4 +39,4 @@ impl Listener for LogListener { fn on_change(&mut self, state: Rc) { log!(Level::Info, "Count changed to {}", state.count); } -} \ No newline at end of file +} diff --git a/examples/todomvc/src/state.rs b/examples/todomvc/src/state.rs index 72251eb..6e02dfe 100644 --- a/examples/todomvc/src/state.rs +++ b/examples/todomvc/src/state.rs @@ -119,8 +119,7 @@ pub struct Entry { pub editing: bool, } -#[derive(Clone, Copy, Debug, EnumIter, Display, PartialEq, Eq, Serialize, Deserialize)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, EnumIter, Display, PartialEq, Eq, Serialize, Deserialize, Default)] pub enum Filter { #[default] All, @@ -145,5 +144,3 @@ impl Filter { } } } - -