A RetroSearch Logo

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

Search Query:

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

ensure $scopedSlots calls always return Arrays · vuejs/vue@c7c13c2 · GitHub

File tree Expand file treeCollapse file tree 6 files changed

+67

-15

lines changed

Filter options

Expand file treeCollapse file tree 6 files changed

+67

-15

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

@@ -55,10 +55,11 @@ export function resolveScopedSlots (

55 55

): { [key: string]: Function } {

56 56

res = res || {}

57 57

for (let i = 0; i < fns.length; i++) {

58 -

if (Array.isArray(fns[i])) {

59 -

resolveScopedSlots(fns[i], res)

58 +

const slot = fns[i]

59 +

if (Array.isArray(slot)) {

60 +

resolveScopedSlots(slot, res)

60 61

} else {

61 -

res[fns[i].key] = fns[i].fn

62 +

res[slot.key] = slot.fn

62 63

}

63 64

}

64 65

return res

Original file line number Diff line number Diff line change

@@ -11,6 +11,7 @@ import {

11 11

import { createElement } from '../vdom/create-element'

12 12

import { installRenderHelpers } from './render-helpers/index'

13 13

import { resolveSlots } from './render-helpers/resolve-slots'

14 +

import { normalizeScopedSlots } from '../vdom/helpers/normalize-scoped-slots'

14 15

import VNode, { createEmptyVNode } from '../vdom/vnode'

15 16 16 17

import { isUpdatingChildComponent } from './lifecycle'

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

63 64

const { render, _parentVnode } = vm.$options

64 65 65 66

if (_parentVnode) {

66 -

vm.$scopedSlots = _parentVnode.data.scopedSlots || emptyObject

67 +

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

67 68

}

68 69 69 70

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

@@ -89,6 +90,10 @@ export function renderMixin (Vue: Class<Component>) {

89 90

vnode = vm._vnode

90 91

}

91 92

}

93 +

// if the returned array contains only a single node, allow it

94 +

if (Array.isArray(vnode) && vnode.length === 1) {

95 +

vnode = vnode[0]

96 +

}

92 97

// return empty vnode in case the render function errored out

93 98

if (!(vnode instanceof VNode)) {

94 99

if (process.env.NODE_ENV !== 'production' && Array.isArray(vnode)) {

Original file line number Diff line number Diff line change

@@ -5,6 +5,7 @@ import { createElement } from './create-element'

5 5

import { resolveInject } from '../instance/inject'

6 6

import { normalizeChildren } from '../vdom/helpers/normalize-children'

7 7

import { resolveSlots } from '../instance/render-helpers/resolve-slots'

8 +

import { normalizeScopedSlots } from '../vdom/helpers/normalize-scoped-slots'

8 9

import { installRenderHelpers } from '../instance/render-helpers/index'

9 10 10 11

import {

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

56 57

this.$options = options

57 58

// pre-resolve slots for renderSlot()

58 59

this.$slots = this.slots()

59 -

this.$scopedSlots = data.scopedSlots || emptyObject

60 +

this.$scopedSlots = normalizeScopedSlots(data.scopedSlots)

60 61

}

61 62 62 63

if (options._scopeId) {

Original file line number Diff line number Diff line change

@@ -0,0 +1,25 @@

1 +

/* @flow */

2 + 3 +

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

4 + 5 +

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

6 +

if (!slots) {

7 +

return emptyObject

8 +

} else if (slots._normalized) {

9 +

return slots

10 +

} else {

11 +

const res = {}

12 +

for (const key in slots) {

13 +

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

14 +

}

15 +

res._normalized = true

16 +

return res

17 +

}

18 +

}

19 + 20 +

function normalizeScopedSlot(fn: Function) {

21 +

return scope => {

22 +

const res = fn(scope)

23 +

return Array.isArray(res) ? res : res ? [res] : res

24 +

}

25 +

}

Original file line number Diff line number Diff line change

@@ -395,11 +395,9 @@ describe('Component scoped slot', () => {

395 395

return { msg: 'hello' }

396 396

},

397 397

render (h) {

398 -

return h('div', [

399 -

this.$scopedSlots.item({

400 -

text: this.msg

401 -

})

402 -

])

398 +

return h('div', this.$scopedSlots.item({

399 +

text: this.msg

400 +

}))

403 401

}

404 402

}

405 403

}

@@ -425,16 +423,38 @@ describe('Component scoped slot', () => {

425 423

return { msg: 'hello' }

426 424

},

427 425

render (h) {

428 -

return h('div', [

429 -

this.$scopedSlots.default({ msg: this.msg })

430 -

])

426 +

return h('div', this.$scopedSlots.default({ msg: this.msg }))

431 427

}

432 428

}

433 429

}

434 430

}).$mount()

435 431

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

436 432

})

437 433 434 +

it('render function usage (default, as root)', () => {

435 +

const vm = new Vue({

436 +

render (h) {

437 +

return h('test', [

438 +

props => h('span', [props.msg])

439 +

])

440 +

},

441 +

components: {

442 +

test: {

443 +

data () {

444 +

return { msg: 'hello' }

445 +

},

446 +

render (h) {

447 +

const res = this.$scopedSlots.default({ msg: this.msg })

448 +

// all scoped slots should be normalized into arrays

449 +

expect(Array.isArray(res)).toBe(true)

450 +

return res

451 +

}

452 +

}

453 +

}

454 +

}).$mount()

455 +

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

456 +

})

457 + 438 458

// #4779

439 459

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

440 460

const Child = {

Original file line number Diff line number Diff line change

@@ -327,11 +327,11 @@ describe('Component slot', () => {

327 327 328 328

it('warn if user directly returns array', () => {

329 329

new Vue({

330 -

template: '<test><div></div></test>',

330 +

template: '<test><div slot="foo"></div><div slot="foo"></div></test>',

331 331

components: {

332 332

test: {

333 333

render () {

334 -

return this.$slots.default

334 +

return this.$slots.foo

335 335

}

336 336

}

337 337

}

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