Skip to content

Format code #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
322 changes: 144 additions & 178 deletions atomic_hooks/macro/src/lib.rs

Large diffs are not rendered by default.

93 changes: 29 additions & 64 deletions seed_hooks/src/ev_handlers.rs
Original file line number Diff line number Diff line change
@@ -1,52 +1,39 @@

use seed::prelude::*;
use crate::state_access::StateAccess;
use atomic_hooks::atom::Atom;

use seed::prelude::*;

pub trait StateAccessEventHandlers<T>
where
T: 'static,
{
fn input_ev<F: FnOnce(&mut T, String) -> () + 'static + Clone,Ms : 'static,>(
fn input_ev<F: FnOnce(&mut T, String) -> () + 'static + Clone, Ms: 'static>(
&self,
event: Ev,
func: F,
) -> seed::EventHandler<Ms>;

fn mouse_ev<
F: FnOnce(&mut T, web_sys::MouseEvent) -> () + 'static + Clone,
Ms : 'static,
>(
fn mouse_ev<F: FnOnce(&mut T, web_sys::MouseEvent) -> () + 'static + Clone, Ms: 'static>(
&self,
event: Ev,
func: F,
) -> seed::EventHandler<Ms>;


fn on_click<
F: FnOnce(&mut T) -> () + 'static + Clone,
Ms : 'static,
>(
fn on_click<F: FnOnce(&mut T) -> () + 'static + Clone, Ms: 'static>(
&self,
func: F,
) -> seed::EventHandler<Ms>;

fn on_input<
F: FnOnce(&mut T, String) -> () + 'static + Clone,
Ms : 'static,
>(
fn on_input<F: FnOnce(&mut T, String) -> () + 'static + Clone, Ms: 'static>(
&self,
func: F,
) -> seed::EventHandler<Ms>;

}

impl<T> StateAccessEventHandlers<T> for StateAccess<T>
where
T: 'static,
{
fn input_ev<F: FnOnce(&mut T, String) -> () + 'static + Clone ,Ms : 'static,>(
fn input_ev<F: FnOnce(&mut T, String) -> () + 'static + Clone, Ms: 'static>(
&self,
event: Ev,
func: F,
Expand All @@ -57,55 +44,43 @@ where
})
}

fn mouse_ev<
F: FnOnce(&mut T, web_sys::MouseEvent) -> () + 'static + Clone,
Ms : 'static,
>(
fn mouse_ev<F: FnOnce(&mut T, web_sys::MouseEvent) -> () + 'static + Clone, Ms: 'static>(
&self,
event: Ev,
func: F,
) -> seed::EventHandler<Ms> {
let accessor = *self;
mouse_ev(event, move |m_ev| {
accessor.update(|val| func(val, m_ev));

})
}

fn on_click<
F: FnOnce(&mut T) -> () + 'static + Clone,
Ms : 'static,
>(
fn on_click<F: FnOnce(&mut T) -> () + 'static + Clone, Ms: 'static>(
&self,
func: F,
) -> seed::EventHandler<Ms> {
let accessor = *self;
mouse_ev(Ev::Click, move |_| {
accessor.update(|val| func(val));

})
}

fn on_input<F: FnOnce(&mut T, String) -> () + 'static + Clone ,Ms : 'static,>(
&self,
func: F,
) -> seed::EventHandler<Ms> {
let accessor = *self;
input_ev(Ev::Input, move |text| {
accessor.update(|val| func(val, text));
})
}


fn on_input<F: FnOnce(&mut T, String) -> () + 'static + Clone, Ms: 'static>(
&self,
func: F,
) -> seed::EventHandler<Ms> {
let accessor = *self;
input_ev(Ev::Input, move |text| {
accessor.update(|val| func(val, text));
})
}
}



impl<T> StateAccessEventHandlers<T> for Atom<T>
where
T: 'static,
{
fn input_ev<F: FnOnce(&mut T, String) -> () + 'static + Clone ,Ms : 'static,>(
fn input_ev<F: FnOnce(&mut T, String) -> () + 'static + Clone, Ms: 'static>(
&self,
event: Ev,
func: F,
Expand All @@ -116,44 +91,34 @@ where
})
}

fn mouse_ev<
F: FnOnce(&mut T, web_sys::MouseEvent) -> () + 'static + Clone,
Ms : 'static,
>(
fn mouse_ev<F: FnOnce(&mut T, web_sys::MouseEvent) -> () + 'static + Clone, Ms: 'static>(
&self,
event: Ev,
func: F,
) -> seed::EventHandler<Ms> {
let accessor = *self;
mouse_ev(event, move |m_ev| {
accessor.update(|val| func(val, m_ev));

})
}

fn on_click<
F: FnOnce(&mut T) -> () + 'static + Clone,
Ms : 'static,
>(
fn on_click<F: FnOnce(&mut T) -> () + 'static + Clone, Ms: 'static>(
&self,
func: F,
) -> seed::EventHandler<Ms> {
let accessor = *self;
mouse_ev(Ev::Click, move |_| {
accessor.update(|val| func(val));

})
}

fn on_input<F: FnOnce(&mut T, String) -> () + 'static + Clone ,Ms : 'static,>(
&self,
func: F,
) -> seed::EventHandler<Ms> {
let accessor = *self;
input_ev(Ev::Input, move |text| {
accessor.update(|val| func(val, text));
})
}


fn on_input<F: FnOnce(&mut T, String) -> () + 'static + Clone, Ms: 'static>(
&self,
func: F,
) -> seed::EventHandler<Ms> {
let accessor = *self;
input_ev(Ev::Input, move |text| {
accessor.update(|val| func(val, text));
})
}
}
13 changes: 7 additions & 6 deletions seed_hooks/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
mod ev_handlers;


mod reactive_enhancements;
mod seed_bind;
mod update_el;
mod utils;
mod reactive_enhancements;
pub use ev_handlers::StateAccessEventHandlers;
pub use seed_bind::{UpdateElLocal, InputBind};
pub use update_el::{StateAccessUpdateEl, LocalUpdateEl2};
pub use reactive_enhancements::ReactiveEnhancements;
pub use seed_bind::{InputBind, UpdateElLocal};
pub use update_el::{LocalUpdateEl2, StateAccessUpdateEl};
pub use utils::{
after_render, after_render_once, get_html_element_by_id, //handle_unmount,
after_render,
after_render_once,
get_html_element_by_id, //handle_unmount,
request_animation_frame,
};
pub use reactive_enhancements::ReactiveEnhancements;

pub use atomic_hooks::*;

Expand Down
Loading