File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
test/unit/features/options Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,8 @@ import { initProxy } from './proxy'
6
6
import { initState } from './state'
7
7
import { initRender } from './render'
8
8
import { initEvents } from './events'
9
- import { initInjections } from './inject'
10
9
import { initLifecycle , callHook } from './lifecycle'
10
+ import { initProvide , initInjections } from './inject'
11
11
import { extend , mergeOptions , formatComponentName } from '../util/index'
12
12
13
13
let uid = 0
@@ -49,8 +49,9 @@ export function initMixin (Vue: Class<Component>) {
49
49
initEvents ( vm )
50
50
initRender ( vm )
51
51
callHook ( vm , 'beforeCreate' )
52
+ initInjections ( vm ) // resolve injections before data/props
52
53
initState ( vm )
53
- initInjections ( vm )
54
+ initProvide ( vm ) // resolve provide after data/props
54
55
callHook ( vm , 'created' )
55
56
56
57
/* istanbul ignore if */
Original file line number Diff line number Diff line change 2
2
3
3
import { hasSymbol } from 'core/util/env'
4
4
5
- export function initInjections ( vm : Component ) {
5
+ export function initProvide ( vm : Component ) {
6
6
const provide = vm . $options . provide
7
- const inject : any = vm . $options . inject
8
7
if ( provide ) {
9
8
vm . _provided = typeof provide === 'function'
10
9
? provide . call ( vm )
11
10
: provide
12
11
}
12
+ }
13
+
14
+ export function initInjections ( vm : Component ) {
15
+ const inject : any = vm . $options . inject
13
16
if ( inject ) {
14
17
// inject is :any because flow is not smart enough to figure out cached
15
18
// isArray here
Original file line number Diff line number Diff line change @@ -115,15 +115,33 @@ describe('Options provide/inject', () => {
115
115
expect ( injected ) . toEqual ( [ false , 2 ] )
116
116
} )
117
117
118
- it ( 'self- inject' , ( ) => {
118
+ it ( 'inject before resolving data/props ' , ( ) => {
119
119
const vm = new Vue ( {
120
120
provide : {
121
121
foo : 1
122
+ }
123
+ } )
124
+
125
+ const child = new Vue ( {
126
+ parent : vm ,
127
+ inject : [ 'foo' ] ,
128
+ data ( ) {
129
+ return {
130
+ bar : this . foo + 1
131
+ }
122
132
} ,
123
- inject : [ 'foo' ]
133
+ props : {
134
+ baz : {
135
+ default ( ) {
136
+ return this . foo + 2
137
+ }
138
+ }
139
+ }
124
140
} )
125
141
126
- expect ( vm . foo ) . toBe ( 1 )
142
+ expect ( child . foo ) . toBe ( 1 )
143
+ expect ( child . bar ) . toBe ( 2 )
144
+ expect ( child . baz ) . toBe ( 3 )
127
145
} )
128
146
129
147
if ( typeof Reflect !== 'undefined' && isNative ( Reflect . ownKeys ) ) {
You can’t perform that action at this time.
0 commit comments