dioxus/packages/core/src/mutations.rs

101 lines
1.7 KiB
Rust
Raw Normal View History

use crate::arena::ElementId;
2021-08-22 21:08:25 +00:00
2022-11-09 03:39:37 +00:00
#[derive(Debug)]
2022-11-09 18:58:11 +00:00
pub struct Mutations<'a> {
2022-11-09 03:39:37 +00:00
pub subtree: usize,
pub template_mutations: Vec<Mutation<'a>>,
2022-11-12 02:29:27 +00:00
pub edits: Vec<Mutation<'a>>,
}
2022-11-09 03:39:37 +00:00
2022-11-09 18:58:11 +00:00
impl<'a> Mutations<'a> {
2022-11-09 03:39:37 +00:00
pub fn new(subtree: usize) -> Self {
Self {
subtree,
2022-11-12 02:29:27 +00:00
edits: Vec::new(),
2022-11-09 03:39:37 +00:00
template_mutations: Vec::new(),
}
}
}
2022-11-09 18:58:11 +00:00
impl<'a> std::ops::Deref for Mutations<'a> {
2022-11-09 03:39:37 +00:00
type Target = Vec<Mutation<'a>>;
fn deref(&self) -> &Self::Target {
2022-11-12 02:29:27 +00:00
&self.edits
2022-11-09 03:39:37 +00:00
}
}
2022-11-09 18:58:11 +00:00
impl std::ops::DerefMut for Mutations<'_> {
2022-11-09 03:39:37 +00:00
fn deref_mut(&mut self) -> &mut Self::Target {
2022-11-12 02:29:27 +00:00
&mut self.edits
2022-11-09 03:39:37 +00:00
}
}
/*
each subtree has its own numbering scheme
*/
2022-11-12 02:29:27 +00:00
#[derive(Debug, PartialEq, Eq)]
pub enum Mutation<'a> {
SetAttribute {
2022-11-03 00:29:18 +00:00
name: &'a str,
value: &'a str,
id: ElementId,
},
LoadTemplate {
name: &'static str,
index: usize,
},
2022-11-02 01:42:29 +00:00
SaveTemplate {
name: &'static str,
m: usize,
},
HydrateText {
path: &'static [u8],
value: &'a str,
id: ElementId,
},
SetText {
value: &'a str,
id: ElementId,
},
ReplacePlaceholder {
2022-11-02 01:42:29 +00:00
m: usize,
2022-11-02 08:00:37 +00:00
path: &'static [u8],
},
AssignId {
path: &'static [u8],
id: ElementId,
},
// Take the current element and replace it with the element with the given id.
Replace {
id: ElementId,
2022-11-04 00:34:42 +00:00
m: usize,
},
2022-11-02 01:42:29 +00:00
CreateElement {
name: &'a str,
namespace: Option<&'a str>,
id: ElementId,
},
CreateText {
value: &'a str,
},
2022-11-04 00:34:42 +00:00
CreatePlaceholder {
id: ElementId,
},
2022-11-02 01:42:29 +00:00
AppendChildren {
m: usize,
},
2021-08-22 21:08:25 +00:00
}