editor.rs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //!
  2. //!
  3. //!
  4. //!
  5. //!
  6. //!
  7. use crate::innerlude::ScopeId;
  8. /// A `DomEdit` represents a serialzied form of the VirtualDom's trait-based API. This allows streaming edits across the
  9. /// network or through FFI boundaries.
  10. #[derive(Debug)]
  11. #[cfg_attr(
  12. feature = "serialize",
  13. derive(serde::Serialize, serde::Deserialize),
  14. serde(tag = "type")
  15. )]
  16. pub enum DomEdit<'bump> {
  17. PushRoot {
  18. id: u64,
  19. },
  20. PopRoot,
  21. AppendChildren {
  22. many: u32,
  23. },
  24. ReplaceWith {
  25. // the first n elements
  26. n: u32,
  27. // the last m elements
  28. m: u32,
  29. },
  30. Remove,
  31. RemoveAllChildren,
  32. CreateTextNode {
  33. text: &'bump str,
  34. id: u64,
  35. },
  36. CreateElement {
  37. tag: &'bump str,
  38. id: u64,
  39. },
  40. CreateElementNs {
  41. tag: &'bump str,
  42. id: u64,
  43. ns: &'static str,
  44. },
  45. CreatePlaceholder {
  46. id: u64,
  47. },
  48. NewEventListener {
  49. event_name: &'static str,
  50. scope: ScopeId,
  51. mounted_node_id: u64,
  52. },
  53. RemoveEventListener {
  54. event: &'static str,
  55. },
  56. SetText {
  57. text: &'bump str,
  58. },
  59. SetAttribute {
  60. field: &'static str,
  61. value: &'bump str,
  62. ns: Option<&'bump str>,
  63. },
  64. RemoveAttribute {
  65. name: &'static str,
  66. },
  67. }
  68. impl DomEdit<'_> {
  69. pub fn is(&self, id: &'static str) -> bool {
  70. match self {
  71. DomEdit::PushRoot { .. } => id == "PushRoot",
  72. DomEdit::PopRoot => id == "PopRoot",
  73. DomEdit::AppendChildren { .. } => id == "AppendChildren",
  74. DomEdit::ReplaceWith { .. } => id == "ReplaceWith",
  75. DomEdit::Remove => id == "Remove",
  76. DomEdit::RemoveAllChildren => id == "RemoveAllChildren",
  77. DomEdit::CreateTextNode { .. } => id == "CreateTextNode",
  78. DomEdit::CreateElement { .. } => id == "CreateElement",
  79. DomEdit::CreateElementNs { .. } => id == "CreateElementNs",
  80. DomEdit::CreatePlaceholder { .. } => id == "CreatePlaceholder",
  81. DomEdit::NewEventListener { .. } => id == "NewEventListener",
  82. DomEdit::RemoveEventListener { .. } => id == "RemoveEventListener",
  83. DomEdit::SetText { .. } => id == "SetText",
  84. DomEdit::SetAttribute { .. } => id == "SetAttribute",
  85. DomEdit::RemoveAttribute { .. } => id == "RemoveAttribute",
  86. }
  87. }
  88. }