2019-05-30 21:24:40 +08:00
|
|
|
// Patch flags are optimization hints generated by the compiler.
|
|
|
|
// when a block with dynamicChildren is encountered during diff, the algorithm
|
|
|
|
// enters "optimized mode". In this mode, we know that the vdom is produced by
|
|
|
|
// a render function generated by the compiler, so the algorithm only needs to
|
|
|
|
// handle updates explicitly marked by these patch flags.
|
|
|
|
|
|
|
|
// Patch flags can be combined using the | bitwise operator and can be checked
|
|
|
|
// using the & operator, e.g.
|
|
|
|
//
|
|
|
|
// const flag = TEXT | CLASS
|
|
|
|
// if (flag & TEXT) { ... }
|
2019-05-30 21:27:14 +08:00
|
|
|
//
|
2020-02-10 02:12:16 +08:00
|
|
|
// Check the `patchElement` function in './renderer.ts' to see how the
|
2019-05-30 21:27:14 +08:00
|
|
|
// flags are handled during diff.
|
2019-05-30 21:24:40 +08:00
|
|
|
|
2019-08-22 23:12:37 +08:00
|
|
|
export const enum PatchFlags {
|
|
|
|
// Indicates an element with dynamic textContent (children fast path)
|
|
|
|
TEXT = 1,
|
|
|
|
|
2019-10-01 09:17:12 +08:00
|
|
|
// Indicates an element with dynamic class binding.
|
2019-08-22 23:12:37 +08:00
|
|
|
CLASS = 1 << 1,
|
|
|
|
|
|
|
|
// Indicates an element with dynamic style
|
|
|
|
// The compiler pre-compiles static string styles into static objects
|
|
|
|
// + detects and hoists inline static objects
|
|
|
|
// e.g. style="color: red" and :style="{ color: 'red' }" both get hoisted as
|
|
|
|
// const style = { color: 'red' }
|
|
|
|
// render() { return e('div', { style }) }
|
|
|
|
STYLE = 1 << 2,
|
|
|
|
|
|
|
|
// Indicates an element that has non-class/style dynamic props.
|
|
|
|
// Can also be on a component that has any dynamic props (includes
|
|
|
|
// class/style). when this flag is present, the vnode also has a dynamicProps
|
|
|
|
// array that contains the keys of the props that may change so the runtime
|
|
|
|
// can diff them faster (without having to worry about removed props)
|
|
|
|
PROPS = 1 << 3,
|
|
|
|
|
|
|
|
// Indicates an element with props with dynamic keys. When keys change, a full
|
|
|
|
// diff is always needed to remove the old key. This flag is mutually
|
|
|
|
// exclusive with CLASS, STYLE and PROPS.
|
|
|
|
FULL_PROPS = 1 << 4,
|
|
|
|
|
2019-09-01 10:17:46 +08:00
|
|
|
// Indicates an element that only needs non-props patching, e.g. ref or
|
2019-10-19 02:01:45 +08:00
|
|
|
// directives (onVnodeXXX hooks). It simply marks the vnode as "need patch",
|
|
|
|
// since every patched vnode checks for refs and onVnodeXXX hooks.
|
2019-10-01 09:17:12 +08:00
|
|
|
// This flag is never directly matched against, it simply serves as a non-zero
|
|
|
|
// value.
|
2019-09-01 10:17:46 +08:00
|
|
|
NEED_PATCH = 1 << 5,
|
|
|
|
|
2019-12-13 09:46:20 +08:00
|
|
|
// Indicates a fragment whose children order doesn't change.
|
|
|
|
STABLE_FRAGMENT = 1 << 6,
|
|
|
|
|
2019-10-02 11:19:48 +08:00
|
|
|
// Indicates a fragment with keyed or partially keyed children
|
2019-12-13 09:46:20 +08:00
|
|
|
KEYED_FRAGMENT = 1 << 7,
|
2019-08-22 23:12:37 +08:00
|
|
|
|
2019-10-02 11:19:48 +08:00
|
|
|
// Indicates a fragment with unkeyed children.
|
2019-12-13 09:46:20 +08:00
|
|
|
UNKEYED_FRAGMENT = 1 << 8,
|
2019-08-22 23:12:37 +08:00
|
|
|
|
|
|
|
// Indicates a component with dynamic slots (e.g. slot that references a v-for
|
|
|
|
// iterated value, or dynamic slot names).
|
|
|
|
// Components with this flag are always force updated.
|
2019-12-13 09:46:20 +08:00
|
|
|
DYNAMIC_SLOTS = 1 << 9,
|
2019-10-04 03:09:09 +08:00
|
|
|
|
|
|
|
// A special flag that indicates that the diffing algorithm should bail out
|
|
|
|
// of optimized mode. This is only on block fragments created by renderSlot()
|
|
|
|
// when encountering non-compiler generated slots (i.e. manually written
|
|
|
|
// render functions, which should always be fully diffed)
|
|
|
|
BAIL = -1
|
2019-08-22 23:12:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// runtime object for public consumption
|
|
|
|
export const PublicPatchFlags = {
|
|
|
|
TEXT: PatchFlags.TEXT,
|
|
|
|
CLASS: PatchFlags.CLASS,
|
|
|
|
STYLE: PatchFlags.STYLE,
|
|
|
|
PROPS: PatchFlags.PROPS,
|
2019-09-01 10:17:46 +08:00
|
|
|
NEED_PATCH: PatchFlags.NEED_PATCH,
|
2019-08-22 23:12:37 +08:00
|
|
|
FULL_PROPS: PatchFlags.FULL_PROPS,
|
2019-10-02 11:19:48 +08:00
|
|
|
KEYED_FRAGMENT: PatchFlags.KEYED_FRAGMENT,
|
|
|
|
UNKEYED_FRAGMENT: PatchFlags.UNKEYED_FRAGMENT,
|
2019-10-04 03:09:09 +08:00
|
|
|
DYNAMIC_SLOTS: PatchFlags.DYNAMIC_SLOTS,
|
|
|
|
BAIL: PatchFlags.BAIL
|
2019-10-02 05:53:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// dev only flag -> name mapping
|
|
|
|
export const PatchFlagNames = {
|
|
|
|
[PatchFlags.TEXT]: `TEXT`,
|
|
|
|
[PatchFlags.CLASS]: `CLASS`,
|
|
|
|
[PatchFlags.STYLE]: `STYLE`,
|
|
|
|
[PatchFlags.PROPS]: `PROPS`,
|
|
|
|
[PatchFlags.NEED_PATCH]: `NEED_PATCH`,
|
|
|
|
[PatchFlags.FULL_PROPS]: `FULL_PROPS`,
|
2019-12-13 09:46:20 +08:00
|
|
|
[PatchFlags.STABLE_FRAGMENT]: `STABLE_FRAGMENT`,
|
2019-10-02 11:19:48 +08:00
|
|
|
[PatchFlags.KEYED_FRAGMENT]: `KEYED_FRAGMENT`,
|
|
|
|
[PatchFlags.UNKEYED_FRAGMENT]: `UNKEYED_FRAGMENT`,
|
2019-10-04 03:09:09 +08:00
|
|
|
[PatchFlags.DYNAMIC_SLOTS]: `DYNAMIC_SLOTS`,
|
|
|
|
[PatchFlags.BAIL]: `BAIL`
|
2019-08-22 23:12:37 +08:00
|
|
|
}
|