Skip to content

Commit

Permalink
perf: skip scoped slots normalization when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 8, 2019
1 parent 7a0dfd0 commit 099f3ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/core/instance/render.js
Expand Up @@ -73,7 +73,8 @@ export function renderMixin (Vue: Class<Component>) {
if (_parentVnode) {
vm.$scopedSlots = normalizeScopedSlots(
_parentVnode.data.scopedSlots,
vm.$slots
vm.$slots,
vm.$scopedSlots
)
}

Expand Down
14 changes: 11 additions & 3 deletions src/core/vdom/helpers/normalize-scoped-slots.js
Expand Up @@ -2,16 +2,22 @@

import { def } from 'core/util/lang'
import { normalizeChildren } from 'core/vdom/helpers/normalize-children'
import { emptyObject } from 'shared/util'

export function normalizeScopedSlots (
slots: { [key: string]: Function } | void,
normalSlots: { [key: string]: Array<VNode> }
normalSlots: { [key: string]: Array<VNode> },
prevSlots?: { [key: string]: Function } | void
): any {
let res
if (!slots) {
res = {}
} else if (slots._normalized) {
return slots
// fast path 1: child component re-render only, parent did not change
return slots._normalized
} else if (slots.$stable && prevSlots && prevSlots !== emptyObject) {
// fast path 2: stable scoped slots, only need to normalize once
return prevSlots
} else {
res = {}
for (const key in slots) {
Expand All @@ -26,7 +32,9 @@ export function normalizeScopedSlots (
res[key] = proxyNormalSlot(normalSlots, key)
}
}
def(res, '_normalized', true)
if (slots) {
(slots: any)._normalized = res
}
def(res, '$stable', slots ? !!slots.$stable : true)
return res
}
Expand Down

0 comments on commit 099f3ba

Please sign in to comment.