mod.rs 658 B

12345678910111213141516171819202122232425
  1. use dioxus_core::prelude::{provide_root_context, try_consume_context};
  2. use std::{any::Any, cell::RefCell, collections::HashMap, rc::Rc};
  3. mod memo;
  4. pub use memo::*;
  5. mod signal;
  6. pub use signal::*;
  7. #[derive(Clone)]
  8. pub(crate) struct GlobalSignalContext {
  9. signal: Rc<RefCell<HashMap<*const (), Box<dyn Any>>>>,
  10. }
  11. pub(crate) fn get_global_context() -> GlobalSignalContext {
  12. match try_consume_context() {
  13. Some(context) => context,
  14. None => {
  15. let context = GlobalSignalContext {
  16. signal: Rc::new(RefCell::new(HashMap::new())),
  17. };
  18. provide_root_context(context).unwrap()
  19. }
  20. }
  21. }