Algorithm
DiffingAlgorithm
The diffing algorithm in Zenaura virtual DOM.
This class is responsible for comparing the old and new virtual DOM trees and generating a list of changes that need to be applied to the real DOM.
The diffing algorithm is implemented in two steps:
- Search: The
Searcher
class traverses the old and new virtual DOM trees and identifies the nodes that have changed. - Update: The
Updater
class applies the changes to the real DOM.
The diffing algorithm is designed to be efficient and performant. It uses a number of techniques to minimize the number of changes that need to be applied to the real DOM.
Attributes:
Searcher
: An instance of theSearcher
class.Updater
: An instance of theUpdater
class.
Methods:
diff(old_tree, new_tree)
: Compares the old and new virtual DOM trees and generates a list of changes that need to be applied to the real DOM.
Example:
# Create an instance of the DiffingAlgorithm class.
diffing_algorithm = DiffingAlgorithm()
# Compare the old and new virtual DOM trees.
changes = diffing_algorithm.diff(old_tree, new_tree)
# Apply the changes to the real DOM.
diffing_algorithm.update(changes)
Source code in zenaura/client/algorithm/algorithm.py
ADD_ATTRIBUTE = 'ADD_ATTRIBUTE'
module-attribute
{ name : "ADD_ATTRIBUTE", context: { "attr_name" : "attr-name", "attr_value" : "attr-value", } }
ADD_NODE = 'ADD_NODE'
module-attribute
{ name : "ADD_NODE", context: { "children" : child-node, } }
NODE_INNER_TEXT = 'NODE_INNER_TEXT'
module-attribute
{ name : "NODE_INNER_TEXT", context: { "text" : "sanitized-text", } }
REMOVE_ATTRIBUTE = 'REMOVE_ATTRIBUTE'
module-attribute
{ name : "REMOVE_ATTRIBUTE", context: { "attr_name" : "attr-name", } }
REMOVE_NODE = 'REMOVE_NODE'
module-attribute
{ name : "REMOVE_NODE", context: { "children" : child-node, } }
REPLACE_ATTRIBUTE = 'REPLACE_ATTRIBUTE'
module-attribute
{ name : "REPLACE_ATTRIBUTE", context: { "attr_name" : "attr-name", "attr_value" : "attr-value", } }