parse.rs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. use dioxus_native_core::node_ref::*;
  2. use dioxus_native_core::state::*;
  3. use dioxus_native_core_macro::*;
  4. #[derive(State, Default, Clone)]
  5. #[allow(dead_code)]
  6. struct Z {
  7. // depends on text, the C component of it's parent and a u16 context
  8. #[parent_dep_state(c, u16)]
  9. d: D,
  10. // depends on just attributes and no context
  11. #[node_dep_state()]
  12. a: A,
  13. // depends on the B component of children and i32 context
  14. #[child_dep_state(b, i32)]
  15. b: B,
  16. // depends on the C component of it's parent and a u8 context
  17. #[parent_dep_state(c, u8)]
  18. c: C,
  19. // this will remain uneffected on updates
  20. n: i32,
  21. }
  22. use dioxus_native_core::state::NodeDepState;
  23. #[derive(Default, Clone, Debug)]
  24. struct A;
  25. impl NodeDepState for A {
  26. type Ctx = ();
  27. type DepState = ();
  28. const NODE_MASK: NodeMask = NodeMask::new(AttributeMask::All, false, false, false);
  29. fn reduce(&mut self, _: NodeView, _: &Self::DepState, _: &()) -> bool {
  30. todo!()
  31. }
  32. }
  33. #[derive(Default, Clone, Debug)]
  34. struct B;
  35. impl ChildDepState for B {
  36. type Ctx = i32;
  37. type DepState = Self;
  38. fn reduce<'a>(
  39. &mut self,
  40. _: NodeView,
  41. _: impl Iterator<Item = &'a Self::DepState>,
  42. _: &i32,
  43. ) -> bool
  44. where
  45. Self::DepState: 'a,
  46. {
  47. todo!()
  48. }
  49. }
  50. #[derive(Default, Clone, Debug)]
  51. struct C;
  52. impl ParentDepState for C {
  53. type Ctx = u8;
  54. type DepState = Self;
  55. fn reduce(&mut self, _: NodeView, _: Option<&Self::DepState>, _: &u8) -> bool {
  56. todo!()
  57. }
  58. }
  59. #[derive(Default, Clone, Debug)]
  60. struct D;
  61. impl ParentDepState for D {
  62. type Ctx = u16;
  63. type DepState = C;
  64. const NODE_MASK: NodeMask = NodeMask::new(AttributeMask::NONE, false, false, true);
  65. fn reduce(&mut self, _: NodeView, _: Option<&Self::DepState>, _: &u16) -> bool {
  66. todo!()
  67. }
  68. }