parse.rs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use dioxus_native_core::state::*;
  2. use dioxus_native_core_macro::*;
  3. #[derive(State, Default, Clone)]
  4. struct Z {
  5. // depends on just attributes and no context
  6. #[node_dep_state()]
  7. x: A,
  8. // depends on attributes, the B component of children and i32 context
  9. #[child_dep_state(B, i32)]
  10. y: B,
  11. // depends on attributes, the C component of it's parent and a u8 context
  12. #[parent_dep_state(C, u8)]
  13. z: C,
  14. }
  15. use dioxus_native_core::state::NodeDepState;
  16. #[derive(Default, Clone)]
  17. struct A;
  18. impl NodeDepState for A {
  19. type Ctx = ();
  20. fn reduce(&mut self, _: NodeView, _: &()) -> bool {
  21. todo!()
  22. }
  23. }
  24. #[derive(Default, Clone)]
  25. struct B;
  26. impl ChildDepState for B {
  27. type Ctx = i32;
  28. type DepState = Self;
  29. fn reduce<'a>(
  30. &mut self,
  31. _: dioxus_native_core::state::NodeView,
  32. _: impl Iterator<Item = &'a Self::DepState>,
  33. _: &i32,
  34. ) -> bool
  35. where
  36. Self::DepState: 'a,
  37. {
  38. todo!()
  39. }
  40. }
  41. #[derive(Default, Clone)]
  42. struct C;
  43. impl ParentDepState for C {
  44. type Ctx = u8;
  45. type DepState = Self;
  46. fn reduce(
  47. &mut self,
  48. _: dioxus_native_core::state::NodeView,
  49. _: Option<&Self::DepState>,
  50. _: &u8,
  51. ) -> bool {
  52. todo!()
  53. }
  54. }