callback.rs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #![allow(clippy::all, unused)]
  2. use std::rc::Rc;
  3. use dioxus_core::prelude::*;
  4. use crate::{AtomRoot, Readable, Writable};
  5. #[derive(Clone)]
  6. pub struct CallbackApi {
  7. root: Rc<AtomRoot>,
  8. }
  9. impl CallbackApi {
  10. // get the current value of the atom
  11. pub fn get<V>(&self, atom: impl Readable<V>) -> &V {
  12. todo!()
  13. }
  14. // get the current value of the atom in its RC container
  15. pub fn get_rc<V>(&self, atom: impl Readable<V>) -> &Rc<V> {
  16. todo!()
  17. }
  18. // set the current value of the atom
  19. pub fn set<V>(&self, atom: impl Writable<V>, value: V) {
  20. todo!()
  21. }
  22. }
  23. #[must_use]
  24. pub fn use_atom_context(cx: &ScopeState) -> &CallbackApi {
  25. todo!()
  26. }
  27. macro_rules! use_callback {
  28. (&$cx:ident, [$($cap:ident),*], move || $body:expr) => {
  29. move || {
  30. $(
  31. #[allow(unused_mut)]
  32. let mut $cap = $cap.to_owned();
  33. )*
  34. $cx.spawn($body);
  35. }
  36. };
  37. }
  38. #[macro_export]
  39. macro_rules! to_owned {
  40. ($($es:ident),+) => {$(
  41. #[allow(unused_mut)]
  42. let mut $es = $es.to_owned();
  43. )*}
  44. }