diff algorithms in the core Vue and React

Virtual DOM

  • js real alternative to DOM objects, change to avoid reflux (re-rendered), real-time rendering to render function by DOM
  • Statement wayfile
  • The output looks likefile

DOM real realization render function generator

  • Setting Propertiesfile
  • render functionfile
  • Rendering functionfile

diff algorithms

  • diff algorithm is actually the DOM compare different kind of algorithm (Virtual relatively more economical performance)
    __ Patch: used to update the DOM tasks __

The comparison rules

  • Contrast same level
    • file
  • No cross-level contrast (no A__ delete __A)file
  • At the same level multiplexing
    • file

Traversal rules

  • Preorder depth-first traversal (towards lower sub traversed from the root node)
    • file
    • 125 called breadth-first
    • 12345 Depth-first

Diff function to achieve

  • Compare ideas rule
      1. The same type, compare attributes, different attributes to generate patches patch{type:'ATTRS',attrs:{class:'xx'} }
      2. The new node does not exist in the original DOM{type:'REMOVE',index:xxx}
      3. Different types of nodes, direct replacement{type:'REPLACE',newNode:xxx}
      4. Text change{type:'TEXT',text:'xxx'}

Guess you like

Origin www.cnblogs.com/qidaoxueyuan/p/12461581.html