+46
-6
lines changedFilter options
+46
-6
lines changed Original file line number Diff line number Diff line change
@@ -38,18 +38,14 @@ export function initInjections (vm: Component) {
38
38
export function resolveInject (inject: any, vm: Component): ?Object {
39
39
if (inject) {
40
40
// inject is :any because flow is not smart enough to figure out cached
41
-
// isArray here
42
-
const isArray = Array.isArray(inject)
43
41
const result = Object.create(null)
44
-
const keys = isArray
45
-
? inject
46
-
: hasSymbol
42
+
const keys = hasSymbol
47
43
? Reflect.ownKeys(inject)
48
44
: Object.keys(inject)
49
45
50
46
for (let i = 0; i < keys.length; i++) {
51
47
const key = keys[i]
52
-
const provideKey = isArray ? key : inject[key]
48
+
const provideKey = inject[key]
53
49
let source = vm
54
50
while (source) {
55
51
if (source._provided && provideKey in source._provided) {
Original file line number Diff line number Diff line change
@@ -182,6 +182,7 @@ strats.watch = function (parentVal: ?Object, childVal: ?Object): ?Object {
182
182
*/
183
183
strats.props =
184
184
strats.methods =
185
+
strats.inject =
185
186
strats.computed = function (parentVal: ?Object, childVal: ?Object): ?Object {
186
187
if (!childVal) return Object.create(parentVal || null)
187
188
if (!parentVal) return childVal
@@ -247,6 +248,19 @@ function normalizeProps (options: Object) {
247
248
options.props = res
248
249
}
249
250
251
+
/**
252
+
* Normalize all injections into Object-based format
253
+
*/
254
+
function normalizeInject (options: Object) {
255
+
const inject = options.inject
256
+
if (Array.isArray(inject)) {
257
+
const normalized = options.inject = {}
258
+
for (let i = 0; i < inject.length; i++) {
259
+
normalized[inject[i]] = inject[i]
260
+
}
261
+
}
262
+
}
263
+
250
264
/**
251
265
* Normalize raw function directives into object format.
252
266
*/
@@ -280,6 +294,7 @@ export function mergeOptions (
280
294
}
281
295
282
296
normalizeProps(child)
297
+
normalizeInject(child)
283
298
normalizeDirectives(child)
284
299
const extendsFrom = child.extends
285
300
if (extendsFrom) {
Original file line number Diff line number Diff line change
@@ -220,6 +220,35 @@ describe('Options provide/inject', () => {
220
220
})
221
221
})
222
222
223
+
it('should extend properly', () => {
224
+
const parent = Vue.extend({
225
+
template: `<span/>`,
226
+
inject: ['foo']
227
+
})
228
+
229
+
const child = parent.extend({
230
+
template: `<span/>`,
231
+
inject: ['bar'],
232
+
created () {
233
+
injected = [this.foo, this.bar]
234
+
}
235
+
})
236
+
237
+
new Vue({
238
+
template: `<div><parent/><child/></div>`,
239
+
provide: {
240
+
foo: 1,
241
+
bar: false
242
+
},
243
+
components: {
244
+
parent,
245
+
child
246
+
}
247
+
}).$mount()
248
+
249
+
expect(injected).toEqual([1, false])
250
+
})
251
+
223
252
it('should warn when injections has been modified', () => {
224
253
const key = 'foo'
225
254
const vm = new Vue({
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