patchFlags.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Patch flags are optimization hints generated by the compiler.
  2. // when a block with dynamicChildren is encountered during diff, the algorithm
  3. // enters "optimized mode". In this mode, we know that the vdom is produced by
  4. // a render function generated by the compiler, so the algorithm only needs to
  5. // handle updates explicitly marked by these patch flags.
  6. // Patch flags can be combined using the | bitwise operator and can be checked
  7. // using the & operator, e.g.
  8. //
  9. // const flag = TEXT | CLASS
  10. // if (flag & TEXT) { ... }
  11. //
  12. // Check the `patchElement` function in './createRednerer.ts' to see how the
  13. // flags are handled during diff.
  14. // Indicates an element with dynamic textContent (children fast path)
  15. export const TEXT = 1
  16. // Indicates an element with dynamic class
  17. export const CLASS = 1 << 1
  18. // Indicates an element with dynamic style
  19. export const STYLE = 1 << 2
  20. // Indicates an element that has non-class/style dynamic props.
  21. // Can also be on a component that has any dynamic props (includes class/style).
  22. // when this flag is present, the vnode also has a dynamicProps array that
  23. // contains the keys of the props that may change so the runtime can diff
  24. // them faster (without having to worry about removed props)
  25. export const PROPS = 1 << 3
  26. // Indicates an element with props with dynamic keys. When keys change, a full
  27. // diff is always needed to remove the old key. This flag is mutually exclusive
  28. // with CLASS, STYLE and PROPS.
  29. export const FULL_PROPS = 1 << 4
  30. // Indicates a fragment or element with keyed or partially-keyed v-for children
  31. export const KEYED = 1 << 5
  32. // Indicates a fragment or element that contains unkeyed v-for children
  33. export const UNKEYED = 1 << 6
  34. // Indicates a component with dynamic slots (e.g. slot that references a v-for
  35. // iterated value, or dynamic slot names).
  36. // Components with this flag are always force updated.
  37. export const DYNAMIC_SLOTS = 1 << 7