Enum mt_dom::patch::Patch [−][src]
pub enum Patch<'a, NS, TAG, ATT, VAL> where
NS: PartialEq + Clone + Debug,
TAG: PartialEq + Clone + Debug,
ATT: PartialEq + Clone + Debug,
VAL: PartialEq + Clone + Debug, {
InsertNode(InsertNode<'a, NS, TAG, ATT, VAL>),
AppendChildren(AppendChildren<'a, NS, TAG, ATT, VAL>),
RemoveNode(RemoveNode<'a, TAG>),
ReplaceNode(ReplaceNode<'a, NS, TAG, ATT, VAL>),
AddAttributes(AddAttributes<'a, NS, TAG, ATT, VAL>),
RemoveAttributes(RemoveAttributes<'a, NS, TAG, ATT, VAL>),
ChangeText(ChangeText<'a>),
ChangeComment(ChangeComment<'a>),
}
Expand description
A Patch encodes an operation that modifies a real DOM element or native UI element
To update the real DOM that a user sees you’ll want to first diff your old virtual dom and new virtual dom.
This diff operation will generate Vec<Patch>
with zero or more patches that, when
applied to your real DOM, will make your real DOM look like your new virtual dom.
Each of the Patch contains TreePath
which contains an array of indexes for each node
that we need to traverse to get the target element.
Consider the following html:
<body>
<main>
<input type="text"/>
<img src="pic.jpg"/>
</main>
<footer>
<a>Link</a>
<nav/>
</footer>
</body>
The corresponding DOM tree would be
.─.
( 0 ) <body>
`-'
/ \
/ \
/ \
▼ ▼
<main> .─. .─. <footer>
( 0 ) ( 1 )
`-' `-'
/ \ | \ '.
/ \ | \ '.
▼ ▼ | \ '.
.─. .─. ▼ ▼ ▼
( 0 ) ( 1 ) .─. .─. .─.
`─' `─' ( 0 ) ( 1 ) ( 2 )
<input> <img> `─' `─' `─'
<a> <Text> <nav>
To traverse to the <nav>
element we follow the TreePath([0,1,2]).
0 - is the root element which is always zero.
1 - is the footer
element since it is the 2nd element of the body.
2 - is the nav
element since it is the 3rd node in the footer
element.
Variants
InsertNode(InsertNode<'a, NS, TAG, ATT, VAL>)
Insert a vector of child nodes to the current node being patch. The usize is the index of of the children of the node to be patch to insert to. The new children will be inserted before this usize
Tuple Fields of InsertNode
0: InsertNode<'a, NS, TAG, ATT, VAL>
AppendChildren(AppendChildren<'a, NS, TAG, ATT, VAL>)
Append a vector of child nodes to a parent node id.
Tuple Fields of AppendChildren
0: AppendChildren<'a, NS, TAG, ATT, VAL>
RemoveNode(RemoveNode<'a, TAG>)
remove node
Tuple Fields of RemoveNode
0: RemoveNode<'a, TAG>
ReplaceNode(ReplaceNode<'a, NS, TAG, ATT, VAL>)
ReplaceNode a node with another node. This typically happens when a node’s tag changes. ex:
Tuple Fields of ReplaceNode
0: ReplaceNode<'a, NS, TAG, ATT, VAL>
AddAttributes(AddAttributes<'a, NS, TAG, ATT, VAL>)
Add attributes that the new node has that the old node does not Note: the attributes is not a reference since attributes of same name are merged to produce a new unify attribute
Tuple Fields of AddAttributes
0: AddAttributes<'a, NS, TAG, ATT, VAL>
RemoveAttributes(RemoveAttributes<'a, NS, TAG, ATT, VAL>)
Remove attributes that the old node had that the new node doesn’t
Tuple Fields of RemoveAttributes
0: RemoveAttributes<'a, NS, TAG, ATT, VAL>
ChangeText(ChangeText<'a>)
Change the text of a Text node.
Tuple Fields of ChangeText
0: ChangeText<'a>
ChangeComment(ChangeComment<'a>)
Change comment content of a Comment node
Tuple Fields of ChangeComment
0: ChangeComment<'a>
Implementations
Trait Implementations
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Performs the conversion.
Auto Trait Implementations
impl<'a, NS, TAG, ATT, VAL> RefUnwindSafe for Patch<'a, NS, TAG, ATT, VAL> where
ATT: RefUnwindSafe,
NS: RefUnwindSafe,
TAG: RefUnwindSafe,
VAL: RefUnwindSafe,
impl<'a, NS, TAG, ATT, VAL> Send for Patch<'a, NS, TAG, ATT, VAL> where
ATT: Sync,
NS: Sync,
TAG: Sync,
VAL: Sync,
impl<'a, NS, TAG, ATT, VAL> Sync for Patch<'a, NS, TAG, ATT, VAL> where
ATT: Sync,
NS: Sync,
TAG: Sync,
VAL: Sync,
impl<'a, NS, TAG, ATT, VAL> UnwindSafe for Patch<'a, NS, TAG, ATT, VAL> where
ATT: RefUnwindSafe,
NS: RefUnwindSafe,
TAG: RefUnwindSafe,
VAL: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more