A RetroSearch Logo

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

Search Query:

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

support providing default values for injections (#6322) · vuejs/vue@88423fc · GitHub

File tree Expand file treeCollapse file tree 3 files changed

+58

-5

lines changed

Filter options

Expand file treeCollapse file tree 3 files changed

+58

-5

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

@@ -49,7 +49,7 @@ export function resolveInject (inject: any, vm: Component): ?Object {

49 49 50 50

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

51 51

const key = keys[i]

52 -

const provideKey = inject[key]

52 +

const provideKey = inject[key].name

53 53

let source = vm

54 54

while (source) {

55 55

if (source._provided && provideKey in source._provided) {

@@ -58,8 +58,15 @@ export function resolveInject (inject: any, vm: Component): ?Object {

58 58

}

59 59

source = source.$parent

60 60

}

61 -

if (process.env.NODE_ENV !== 'production' && !source) {

62 -

warn(`Injection "${key}" not found`, vm)

61 +

if (!source) {

62 +

if ('default' in inject[key]) {

63 +

const provideDefault = inject[key].default

64 +

result[key] = typeof provideDefault === 'function'

65 +

? provideDefault.call(vm)

66 +

: provideDefault

67 +

} else if (process.env.NODE_ENV !== 'production') {

68 +

warn(`Injection "${key}" not found`, vm)

69 +

}

63 70

}

64 71

}

65 72

return result

Original file line number Diff line number Diff line change

@@ -270,10 +270,17 @@ function normalizeProps (options: Object) {

270 270

*/

271 271

function normalizeInject (options: Object) {

272 272

const inject = options.inject

273 +

const normalized = options.inject = {}

273 274

if (Array.isArray(inject)) {

274 -

const normalized = options.inject = {}

275 275

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

276 -

normalized[inject[i]] = inject[i]

276 +

normalized[inject[i]] = { name: inject[i] }

277 +

}

278 +

} else if (isPlainObject(inject)) {

279 +

for (const key in inject) {

280 +

const val = inject[key]

281 +

normalized[key] = isPlainObject(val)

282 +

? extend({ name: key }, val)

283 +

: { name: val }

277 284

}

278 285

}

279 286

}

Original file line number Diff line number Diff line change

@@ -370,6 +370,45 @@ describe('Options provide/inject', () => {

370 370

expect(`Injection "__ob__" not found`).not.toHaveBeenWarned()

371 371

})

372 372 373 +

// Github issue #6097

374 +

it('should not warn when injections cannot be found but have default value', () => {

375 +

const vm = new Vue({})

376 +

new Vue({

377 +

parent: vm,

378 +

inject: {

379 +

foo: { default: 1 },

380 +

bar: { default: false },

381 +

baz: { default: undefined }

382 +

},

383 +

created () {}

384 +

})

385 +

expect(`Injection "foo" not found`).not.toHaveBeenWarned()

386 +

expect(`Injection "bar" not found`).not.toHaveBeenWarned()

387 +

expect(`Injection "baz" not found`).not.toHaveBeenWarned()

388 +

})

389 + 390 +

it('should use provided value even if inject has default', () => {

391 +

const vm = new Vue({

392 +

provide: {

393 +

foo: 1,

394 +

bar: false,

395 +

baz: undefined

396 +

}

397 +

})

398 +

new Vue({

399 +

parent: vm,

400 +

inject: {

401 +

foo: { default: 2 },

402 +

bar: { default: 2 },

403 +

baz: { default: 2 }

404 +

},

405 +

created () {

406 +

injected = [this.foo, this.bar, this.baz]

407 +

}

408 +

})

409 +

expect(injected).toEqual([1, false, undefined])

410 +

})

411 + 373 412

// Github issue #6008

374 413

it('should merge provide from mixins (objects)', () => {

375 414

const mixinA = { provide: { foo: 'foo' }}

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