A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/vuejs/vue/commit/5d52262f1ce56d080c3438c4773a81dc5c8397aa below:

expose all slots on $scopedSlots as functions · vuejs/vue@5d52262 · GitHub

File tree Expand file treeCollapse file tree 5 files changed

+43

-9

lines changed

Filter options

Expand file treeCollapse file tree 5 files changed

+43

-9

lines changed Original file line number Diff line number Diff line change

@@ -1,6 +1,7 @@

1 1

/* @flow */

2 2 3 3

import type VNode from 'core/vdom/vnode'

4 +

import { emptyObject } from 'core/util/index'

4 5 5 6

/**

6 7

* Runtime helper for resolving raw children VNodes into a slot object.

@@ -9,10 +10,10 @@ export function resolveSlots (

9 10

children: ?Array<VNode>,

10 11

context: ?Component

11 12

): { [key: string]: Array<VNode> } {

12 -

const slots = {}

13 -

if (!children) {

14 -

return slots

13 +

if (!children || !children.length) {

14 +

return emptyObject

15 15

}

16 +

const slots = {}

16 17

for (let i = 0, l = children.length; i < l; i++) {

17 18

const child = children[i]

18 19

const data = child.data

Original file line number Diff line number Diff line change

@@ -64,7 +64,10 @@ export function renderMixin (Vue: Class<Component>) {

64 64

const { render, _parentVnode } = vm.$options

65 65 66 66

if (_parentVnode) {

67 -

vm.$scopedSlots = normalizeScopedSlots(_parentVnode.data.scopedSlots)

67 +

vm.$scopedSlots = normalizeScopedSlots(

68 +

_parentVnode.data.scopedSlots,

69 +

vm.$slots

70 +

)

68 71

}

69 72 70 73

// set parent vnode. this allows render functions to have access

Original file line number Diff line number Diff line change

@@ -57,7 +57,7 @@ export function FunctionalRenderContext (

57 57

this.$options = options

58 58

// pre-resolve slots for renderSlot()

59 59

this.$slots = this.slots()

60 -

this.$scopedSlots = normalizeScopedSlots(data.scopedSlots)

60 +

this.$scopedSlots = normalizeScopedSlots(data.scopedSlots, this.$slots)

61 61

}

62 62 63 63

if (options._scopeId) {

Original file line number Diff line number Diff line change

@@ -2,19 +2,31 @@

2 2 3 3

import { emptyObject } from 'core/util/index'

4 4 5 -

export function normalizeScopedSlots (slots: { [key: string]: Function } | void): any {

5 +

export function normalizeScopedSlots (

6 +

slots: { [key: string]: Function } | void,

7 +

normalSlots: { [key: string]: Array<VNode> }

8 +

): any {

9 +

let res

6 10

if (!slots) {

7 -

return emptyObject

11 +

if (normalSlots === emptyObject) {

12 +

return emptyObject

13 +

}

14 +

res = {}

8 15

} else if (slots._normalized) {

9 16

return slots

10 17

} else {

11 -

const res = {}

18 +

res = {}

12 19

for (const key in slots) {

13 20

res[key] = normalizeScopedSlot(slots[key])

14 21

}

15 22

res._normalized = true

16 -

return res

17 23

}

24 +

if (normalSlots !== emptyObject) {

25 +

for (const key in normalSlots) {

26 +

res[key] = () => normalSlots[key]

27 +

}

28 +

}

29 +

return res

18 30

}

19 31 20 32

function normalizeScopedSlot(fn: Function) {

Original file line number Diff line number Diff line change

@@ -455,6 +455,24 @@ describe('Component scoped slot', () => {

455 455

expect(vm.$el.outerHTML).toBe('<span>hello</span>')

456 456

})

457 457 458 +

// new in 2.6, unifying all slots as functions

459 +

it('non-scoped slots should also be available on $scopedSlots', () => {

460 +

const vm = new Vue({

461 +

template: `<foo>before <div slot="bar">{{ $slot.msg }}</div> after</foo>`,

462 +

components: {

463 +

foo: {

464 +

render(h) {

465 +

return h('div', [

466 +

this.$scopedSlots.default(),

467 +

this.$scopedSlots.bar({ msg: 'hi' })

468 +

])

469 +

}

470 +

}

471 +

}

472 +

}).$mount()

473 +

expect(vm.$el.innerHTML).toBe(`before after<div>hi</div>`)

474 +

})

475 + 458 476

// #4779

459 477

it('should support dynamic slot target', done => {

460 478

const Child = {

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4