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'
66import { initState } from './state'
77import { initRender } from './render'
88import { initEvents } from './events'
9- import { initInjections } from './inject'
109import { initLifecycle , callHook } from './lifecycle'
10+ import { initProvide , initInjections } from './inject'
1111import { extend , mergeOptions , formatComponentName } from '../util/index'
1212
1313let uid = 0
@@ -49,8 +49,9 @@ export function initMixin (Vue: Class<Component>) {
4949 initEvents ( vm )
5050 initRender ( vm )
5151 callHook ( vm , 'beforeCreate' )
52+ initInjections ( vm ) // resolve injections before data/props
5253 initState ( vm )
53- initInjections ( vm )
54+ initProvide ( vm ) // resolve provide after data/props
5455 callHook ( vm , 'created' )
5556
5657 /* istanbul ignore if */
Original file line number Diff line number Diff line change 22
33import { hasSymbol } from 'core/util/env'
44
5- export function initInjections ( vm : Component ) {
5+ export function initProvide ( vm : Component ) {
66 const provide = vm . $options . provide
7- const inject : any = vm . $options . inject
87 if ( provide ) {
98 vm . _provided = typeof provide === 'function'
109 ? provide . call ( vm )
1110 : provide
1211 }
12+ }
13+
14+ export function initInjections ( vm : Component ) {
15+ const inject : any = vm . $options . inject
1316 if ( inject ) {
1417 // inject is :any because flow is not smart enough to figure out cached
1518 // isArray here
Original file line number Diff line number Diff line change @@ -115,15 +115,33 @@ describe('Options provide/inject', () => {
115115 expect ( injected ) . toEqual ( [ false , 2 ] )
116116 } )
117117
118- it ( 'self- inject' , ( ) => {
118+ it ( 'inject before resolving data/props ' , ( ) => {
119119 const vm = new Vue ( {
120120 provide : {
121121 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+ }
122132 } ,
123- inject : [ 'foo' ]
133+ props : {
134+ baz : {
135+ default ( ) {
136+ return this . foo + 2
137+ }
138+ }
139+ }
124140 } )
125141
126- expect ( vm . foo ) . toBe ( 1 )
142+ expect ( child . foo ) . toBe ( 1 )
143+ expect ( child . bar ) . toBe ( 2 )
144+ expect ( child . baz ) . toBe ( 3 )
127145 } )
128146
129147 if ( typeof Reflect !== 'undefined' && isNative ( Reflect . ownKeys ) ) {
You can’t perform that action at this time.
0 commit comments