Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
wainwrightmark authored and intendednull committed Mar 16, 2023
1 parent 7488131 commit b046f6b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
2 changes: 1 addition & 1 deletion crates/yewdux-input/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
25 changes: 13 additions & 12 deletions crates/yewdux-macros/src/store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use darling::{FromDeriveInput, util::PathList};
use darling::{util::PathList, FromDeriveInput};
use proc_macro2::TokenStream;
use quote::quote;
use syn::DeriveInput;
Expand All @@ -8,22 +8,25 @@ use syn::DeriveInput;
struct Opts {
storage: Option<String>,
storage_tab_sync: bool,
listener: PathList
listener: PathList,
}

pub(crate) fn derive(input: DeriveInput) -> TokenStream {
let opts = Opts::from_derive_input(&input).expect("Invalid options");
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) => {
Expand All @@ -46,8 +49,6 @@ pub(crate) fn derive(input: DeriveInput) -> TokenStream {
quote!()
};



quote! {
#[cfg(target_arch = "wasm32")]
fn new() -> Self {
Expand Down
20 changes: 9 additions & 11 deletions crates/yewdux/src/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ pub trait Listener: 'static {
fn on_change(&mut self, state: Rc<Self::Store>);
}

struct ListenerStore<L : Listener>(Option<SubscriberId<L::Store>>);
impl<L : Listener> Store for Mrc<ListenerStore<L>> {
fn new() -> Self {
ListenerStore(None).into()
}
struct ListenerStore<L: Listener>(Option<SubscriberId<L::Store>>);
impl<L: Listener> Store for Mrc<ListenerStore<L>> {
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.
Expand All @@ -28,9 +28,7 @@ pub fn init_listener<L: Listener>(listener: L) {
dispatch::subscribe_silent(move |state| listener.borrow_mut().on_change(state))
};

dispatch::reduce_mut(|state: &mut Mrc<ListenerStore<L>>| {
state.borrow_mut().0 = Some(id)
});
dispatch::reduce_mut(|state: &mut Mrc<ListenerStore<L>>| state.borrow_mut().0 = Some(id));
}

#[cfg(test)]
Expand Down
8 changes: 5 additions & 3 deletions examples/persistent/src/main.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -29,12 +32,11 @@ fn main() {
yew::Renderer::<App>::new().render();
}


struct LogListener;
impl Listener for LogListener {
type Store = State;

fn on_change(&mut self, state: Rc<Self::Store>) {
log!(Level::Info, "Count changed to {}", state.count);
}
}
}
5 changes: 1 addition & 4 deletions examples/todomvc/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -145,5 +144,3 @@ impl Filter {
}
}
}


0 comments on commit b046f6b

Please sign in to comment.