pub fn patch(&mut self, new: Node) -> Result<(), JsValue> {
		if self.id == 0 {
			return Err("node not mounted yet".into());
		}

		// Check, if nodes are considered similar enough to be merged and not
		// replaced destructively
		if self.key != new.key
			|| match &self.contents {
				NodeContents::Text(_) => match &new.contents {
					NodeContents::Element(_) => true,
					NodeContents::Text(_) => false,
				},
				NodeContents::Element(cont) => match &new.contents {
					NodeContents::Text(_) => true,
					NodeContents::Element(new_cont) => new_cont.tag != cont.tag,
				},
			} {
			return Node::replace_node(self, new);
		}

		self.key = new.key;
		match &mut self.contents {
			NodeContents::Text(ref mut old_text) => {
				if let NodeContents::Text(new_text) = &new.contents {
					if old_text != new_text {
						*old_text = new_text.clone();
						self.element.get()?.set_text_content(Some(old_text));
					}
				}
			}
			NodeContents::Element(ref mut old_cont) => {
				if let NodeContents::Element(new_cont) = new.contents {
					old_cont.attrs.patch(&mut self.element, new_cont.attrs)?;

					Node::patch_children(
						&mut self.element,
						&mut old_cont.children,
						new_cont.children,
					)?;
				}
			}
		};
		Ok(())
	}
// Patch possibly changed subtree into self and apply changes to the DOM.
// Node must be already mounted.
Patch possibly changed subtree into self and apply changes to the DOM.
Node must be already mounted.
Patch possibly changed subtree into self and apply changes to the DOM . Node must be already mounted .
pub fn patch(&mut self, new: Node) -> Result<(), JsValue> {
		if self.id == 0 {
			return Err("node not mounted yet".into());
		}
		// Check, if nodes are considered similar enough to be merged and not
		// replaced destructively
		if self.key != new.key
			|| match &self.contents {
				NodeContents::Text(_) => match &new.contents {
					NodeContents::Element(_) => true,
					NodeContents::Text(_) => false,
				},
				NodeContents::Element(cont) => match &new.contents {
					NodeContents::Text(_) => true,
					NodeContents::Element(new_cont) => new_cont.tag != cont.tag,
				},
			} {
			return Node::replace_node(self, new);
		}
		self.key = new.key;
		match &mut self.contents {
			NodeContents::Text(ref mut old_text) => {
				if let NodeContents::Text(new_text) = &new.contents {
					if old_text != new_text {
						*old_text = new_text.clone();
						self.element.get()?.set_text_content(Some(old_text));
					}
				}
			}
			NodeContents::Element(ref mut old_cont) => {
				if let NodeContents::Element(new_cont) = new.contents {
					old_cont.attrs.patch(&mut self.element, new_cont.attrs)?;
					Node::patch_children(
						&mut self.element,
						&mut old_cont.children,
						new_cont.children,
					)?;
				}
			}
		};
		Ok(())
	}
pub fn patch ( & mut self , new : Node ) -> Result < ( ) , JsValue > { if self . id == 0 { return Err ( " " . into ( ) ) ; } // Check, if nodes are considered similar enough to be merged and not // replaced destructively if self . key != new . key || match & self . contents { NodeContents :: Text ( _ ) => match & new . contents { NodeContents :: Element ( _ ) => true , NodeContents :: Text ( _ ) => false , } , NodeContents :: Element ( cont ) => match & new . contents { NodeContents :: Text ( _ ) => true , NodeContents :: Element ( new_cont ) => new_cont . tag != cont . tag , } , } { return Node :: replace_node ( self , new ) ; } self . key = new . key ; match & mut self . contents { NodeContents :: Text ( ref mut old_text ) => { if let NodeContents :: Text ( new_text ) = & new . contents { if old_text != new_text { * old_text = new_text . clone ( ) ; self . element . get ( ) ? . set_text_content ( Some ( old_text ) ) ; } } } NodeContents :: Element ( ref mut old_cont ) => { if let NodeContents :: Element ( new_cont ) = new . contents { old_cont . attrs . patch ( & mut self . element , new_cont . attrs ) ? ; Node :: patch_children ( & mut self . element , & mut old_cont . children , new_cont . children , ) ? ; } } } ; Ok ( ( ) ) }
Patch possibly changed subtree into self and apply changes to the DOM.
Patch possibly changed subtree into self and apply changes to the DOM .
&mut self
new
Node