wip: more work on suspense and documentation
This commit is contained in:
1 parent
4837d8e741
commit
37ed4bed8c
14 files changed
+240
-192
No files matched your search
+26
-11
@@ -1,5 +1,3 @@
|
||||
//! Serialization
|
||||
//! -------------
|
||||
//!
|
||||
//!
|
||||
//!
|
||||
@@ -7,7 +5,7 @@
|
||||
//!
|
||||
//!
|
||||
|
||||
use crate::{innerlude::ScopeIdx, RealDomNode};
|
||||
use crate::{innerlude::ScopeId, RealDomNode};
|
||||
|
||||
/// The `DomEditor` provides an imperative interface for the Diffing algorithm to plan out its changes.
|
||||
///
|
||||
@@ -18,6 +16,7 @@ use crate::{innerlude::ScopeIdx, RealDomNode};
|
||||
pub struct DomEditor<'real, 'bump> {
|
||||
pub edits: &'real mut Vec<DomEdit<'bump>>,
|
||||
}
|
||||
|
||||
use DomEdit::*;
|
||||
impl<'real, 'bump> DomEditor<'real, 'bump> {
|
||||
pub fn new(edits: &'real mut Vec<DomEdit<'bump>>) -> Self {
|
||||
@@ -29,35 +28,44 @@ impl<'real, 'bump> DomEditor<'real, 'bump> {
|
||||
let id = root.as_u64();
|
||||
self.edits.push(PushRoot { id });
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn pop(&mut self) {
|
||||
self.edits.push(PopRoot {});
|
||||
}
|
||||
|
||||
// Add Nodes to the dom
|
||||
// add m nodes from the stack
|
||||
#[inline]
|
||||
pub(crate) fn append_children(&mut self, many: u32) {
|
||||
self.edits.push(AppendChildren { many });
|
||||
}
|
||||
|
||||
// replace the n-m node on the stack with the m nodes
|
||||
// ends with the last element of the chain on the top of the stack
|
||||
#[inline]
|
||||
pub(crate) fn replace_with(&mut self, many: u32) {
|
||||
self.edits.push(ReplaceWith { many });
|
||||
}
|
||||
|
||||
// Remove Nodesfrom the dom
|
||||
#[inline]
|
||||
pub(crate) fn remove(&mut self) {
|
||||
self.edits.push(Remove);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn remove_all_children(&mut self) {
|
||||
self.edits.push(RemoveAllChildren);
|
||||
}
|
||||
|
||||
// Create
|
||||
#[inline]
|
||||
pub(crate) fn create_text_node(&mut self, text: &'bump str, id: RealDomNode) {
|
||||
let id = id.as_u64();
|
||||
self.edits.push(CreateTextNode { text, id });
|
||||
}
|
||||
|
||||
pub(crate) fn create_element(
|
||||
&mut self,
|
||||
tag: &'static str,
|
||||
@@ -81,25 +89,30 @@ impl<'real, 'bump> DomEditor<'real, 'bump> {
|
||||
pub(crate) fn new_event_listener(
|
||||
&mut self,
|
||||
event: &'static str,
|
||||
scope: ScopeIdx,
|
||||
scope: ScopeId,
|
||||
element_id: usize,
|
||||
realnode: RealDomNode,
|
||||
) {
|
||||
self.edits.push(NewEventListener {
|
||||
scope,
|
||||
event,
|
||||
idx: element_id,
|
||||
node: realnode.as_u64(),
|
||||
event_name: event,
|
||||
element_id,
|
||||
mounted_node_id: realnode.as_u64(),
|
||||
});
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn remove_event_listener(&mut self, event: &'static str) {
|
||||
self.edits.push(RemoveEventListener { event });
|
||||
}
|
||||
|
||||
// modify
|
||||
#[inline]
|
||||
pub(crate) fn set_text(&mut self, text: &'bump str) {
|
||||
self.edits.push(SetText { text });
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn set_attribute(
|
||||
&mut self,
|
||||
field: &'static str,
|
||||
@@ -108,6 +121,8 @@ impl<'real, 'bump> DomEditor<'real, 'bump> {
|
||||
) {
|
||||
self.edits.push(SetAttribute { field, value, ns });
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn remove_attribute(&mut self, name: &'static str) {
|
||||
self.edits.push(RemoveAttribute { name });
|
||||
}
|
||||
@@ -151,10 +166,10 @@ pub enum DomEdit<'bump> {
|
||||
id: u64,
|
||||
},
|
||||
NewEventListener {
|
||||
event: &'static str,
|
||||
scope: ScopeIdx,
|
||||
node: u64,
|
||||
idx: usize,
|
||||
event_name: &'static str,
|
||||
scope: ScopeId,
|
||||
mounted_node_id: u64,
|
||||
element_id: usize,
|
||||
},
|
||||
RemoveEventListener {
|
||||
event: &'static str,
|
||||
|
||||
Reference in new issue
Block a user