react_rs_elements/
events.rs1pub struct Event {
2 pub event_type: String,
3}
4
5impl Event {
6 pub fn new(event_type: impl Into<String>) -> Self {
7 Self {
8 event_type: event_type.into(),
9 }
10 }
11}
12
13pub struct EventHandler {
14 pub event_type: String,
15 pub handler: Box<dyn Fn(Event)>,
16}
17
18impl EventHandler {
19 pub fn new<F>(event_type: impl Into<String>, handler: F) -> Self
20 where
21 F: Fn(Event) + 'static,
22 {
23 Self {
24 event_type: event_type.into(),
25 handler: Box::new(handler),
26 }
27 }
28
29 pub fn event_type(&self) -> &str {
30 &self.event_type
31 }
32
33 pub fn invoke(&self, event: Event) {
34 (self.handler)(event);
35 }
36}