♻️ Major code restructuring
This commit is contained in:
parent
a96e203bb3
commit
fa66d628a0
221 changed files with 228 additions and 315 deletions
34
src/core/action/all.rs
Normal file
34
src/core/action/all.rs
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
use crate::core::action::{Action, ActionsList};
|
||||
use crate::{Handle, LazyStatic};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::sync::RwLock;
|
||||
|
||||
pub type KeyAction = (Handle, Option<Handle>, Option<String>);
|
||||
|
||||
// Registered actions.
|
||||
static ACTIONS: LazyStatic<RwLock<HashMap<KeyAction, ActionsList>>> =
|
||||
LazyStatic::new(|| RwLock::new(HashMap::new()));
|
||||
|
||||
pub fn add_action(action: Action) {
|
||||
let mut actions = ACTIONS.write().unwrap();
|
||||
let key_action = (
|
||||
action.handle(),
|
||||
action.referer_handle(),
|
||||
action.referer_id(),
|
||||
);
|
||||
if let Some(list) = actions.get_mut(&key_action) {
|
||||
list.add(action);
|
||||
} else {
|
||||
actions.insert(key_action, ActionsList::new(action));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn dispatch_actions<B, F>(key_action: KeyAction, f: F)
|
||||
where
|
||||
F: FnMut(&Action) -> B,
|
||||
{
|
||||
if let Some(list) = ACTIONS.read().unwrap().get(&key_action) {
|
||||
list.iter_map(f)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue