Browse Source

refactor: avoid using immutable object for $slot

libs like Avoiraz assumes $slots is mutable, need backwards
compat.
dev
Evan You 6 years ago
parent
commit
8eea6b07c4
  1. 3
      src/core/instance/render-helpers/resolve-slots.js
  2. 13
      src/core/vdom/helpers/normalize-scoped-slots.js

3
src/core/instance/render-helpers/resolve-slots.js

@ -1,7 +1,6 @@
/* @flow */
import type VNode from 'core/vdom/vnode'
import { emptyObject } from 'core/util/index'
/**
* Runtime helper for resolving raw children VNodes into a slot object.
@ -11,7 +10,7 @@ export function resolveSlots (
context: ?Component
): { [key: string]: Array<VNode> } {
if (!children || !children.length) {
return emptyObject
return {}
}
const slots = {}
for (let i = 0, l = children.length; i < l; i++) {

13
src/core/vdom/helpers/normalize-scoped-slots.js

@ -1,16 +1,11 @@
/* @flow */
import { emptyObject } from 'core/util/index'
export function normalizeScopedSlots (
slots: { [key: string]: Function } | void,
normalSlots: { [key: string]: Array<VNode> }
): any {
let res
if (!slots) {
if (normalSlots === emptyObject) {
return emptyObject
}
res = {}
} else if (slots._normalized) {
return slots
@ -19,14 +14,12 @@ export function normalizeScopedSlots (
for (const key in slots) {
res[key] = normalizeScopedSlot(slots[key])
}
res._normalized = true
}
// expose normal slots on scopedSlots
if (normalSlots !== emptyObject) {
for (const key in normalSlots) {
res[key] = () => normalSlots[key]
}
for (const key in normalSlots) {
res[key] = () => normalSlots[key]
}
res._normalized = true
return res
}

Loading…
Cancel
Save