File tree Expand file tree Collapse file tree 4 files changed +64
-40
lines changed Expand file tree Collapse file tree 4 files changed +64
-40
lines changed Original file line number Diff line number Diff line change @@ -117,32 +117,12 @@ export function resolveConstructorOptions (Ctor: Class<Component>) {
117117function resolveModifiedOptions ( Ctor : Class < Component > ) : ?Object {
118118 let modified
119119 const latest = Ctor . options
120- const extended = Ctor . extendOptions
121120 const sealed = Ctor . sealedOptions
122121 for ( const key in latest ) {
123122 if ( latest [ key ] !== sealed [ key ] ) {
124123 if ( ! modified ) modified = { }
125- modified [ key ] = dedupe ( latest [ key ] , extended [ key ] , sealed [ key ] )
124+ modified [ key ] = latest [ key ]
126125 }
127126 }
128127 return modified
129128}
130-
131- function dedupe ( latest , extended , sealed ) {
132- // compare latest and sealed to ensure lifecycle hooks won't be duplicated
133- // between merges
134- if ( Array . isArray ( latest ) ) {
135- const res = [ ]
136- sealed = Array . isArray ( sealed ) ? sealed : [ sealed ]
137- extended = Array . isArray ( extended ) ? extended : [ extended ]
138- for ( let i = 0 ; i < latest . length ; i ++ ) {
139- // push original options and not sealed options to exclude duplicated options
140- if ( extended . indexOf ( latest [ i ] ) >= 0 || sealed . indexOf ( latest [ i ] ) < 0 ) {
141- res . push ( latest [ i ] )
142- }
143- }
144- return res
145- } else {
146- return latest
147- }
148- }
Original file line number Diff line number Diff line change @@ -140,13 +140,26 @@ function mergeHook (
140140 parentVal : ?Array < Function > ,
141141 childVal : ?Function | ?Array < Function >
142142) : ?Array < Function > {
143- return childVal
143+ const res = childVal
144144 ? parentVal
145145 ? parentVal . concat ( childVal )
146146 : Array . isArray ( childVal )
147147 ? childVal
148148 : [ childVal ]
149149 : parentVal
150+ return res
151+ ? dedupeHooks ( res )
152+ : res
153+ }
154+
155+ function dedupeHooks ( hooks ) {
156+ const res = [ ]
157+ for ( let i = 0 ; i < hooks . length ; i ++ ) {
158+ if ( res . indexOf ( hooks [ i ] ) === - 1 ) {
159+ res . push ( hooks [ i ] )
160+ }
161+ }
162+ return res
150163}
151164
152165LIFECYCLE_HOOKS . forEach ( hook => {
@@ -376,7 +389,7 @@ export function mergeOptions (
376389 }
377390
378391 if ( typeof child === 'function' ) {
379- child = child . extendOptions
392+ child = child . options
380393 }
381394
382395 normalizeProps ( child , vm )
Original file line number Diff line number Diff line change @@ -167,4 +167,31 @@ describe('Global API: mixin', () => {
167167 it ( 'chain call' , ( ) => {
168168 expect ( Vue . mixin ( { } ) ) . toBe ( Vue )
169169 } )
170+
171+ // #9198
172+ it ( 'should not mix global mixin lifecycle hook twice' , ( ) => {
173+ const spy = jasmine . createSpy ( 'global mixed in lifecycle hook' )
174+ Vue . mixin ( {
175+ created : spy
176+ } )
177+
178+ const mixin1 = Vue . extend ( {
179+ methods : {
180+ a ( ) { }
181+ }
182+ } )
183+
184+ const mixin2 = Vue . extend ( {
185+ mixins : [ mixin1 ]
186+ } )
187+
188+ const Child = Vue . extend ( {
189+ mixins : [ mixin2 ] ,
190+ } )
191+
192+ const vm = new Child ( )
193+
194+ expect ( typeof vm . $options . methods . a ) . toBe ( 'function' )
195+ expect ( spy . calls . count ( ) ) . toBe ( 1 )
196+ } )
170197} )
Original file line number Diff line number Diff line change @@ -110,31 +110,35 @@ describe('Options mixins', () => {
110110 expect ( vm . $options . directives . c ) . toBeDefined ( )
111111 } )
112112
113- it ( 'should not mix global mixined lifecycle hook twice' , ( ) => {
114- const spy = jasmine . createSpy ( 'global mixed in lifecycle hook' )
115- Vue . mixin ( {
116- created ( ) {
117- spy ( )
118- }
119- } )
113+ it ( 'should accept further extended constructors as mixins' , ( ) => {
114+ const spy1 = jasmine . createSpy ( 'mixinA' )
115+ const spy2 = jasmine . createSpy ( 'mixinB' )
120116
121- const mixin1 = Vue . extend ( {
117+ const mixinA = Vue . extend ( {
118+ created : spy1 ,
119+ directives : {
120+ c : { }
121+ } ,
122122 methods : {
123- a ( ) { }
123+ a : function ( ) { }
124124 }
125125 } )
126126
127- const mixin2 = Vue . extend ( {
128- mixins : [ mixin1 ] ,
127+ const mixinB = mixinA . extend ( {
128+ created : spy2
129129 } )
130130
131- const Child = Vue . extend ( {
132- mixins : [ mixin2 ] ,
131+ const vm = new Vue ( {
132+ mixins : [ mixinB ] ,
133+ methods : {
134+ b : function ( ) { }
135+ }
133136 } )
134137
135- const vm = new Child ( )
136-
137- expect ( typeof vm . $options . methods . a ) . toBe ( 'function' )
138- expect ( spy . calls . count ( ) ) . toBe ( 1 )
138+ expect ( spy1 ) . toHaveBeenCalledTimes ( 1 )
139+ expect ( spy2 ) . toHaveBeenCalledTimes ( 1 )
140+ expect ( vm . a ) . toBeDefined ( )
141+ expect ( vm . b ) . toBeDefined ( )
142+ expect ( vm . $options . directives . c ) . toBeDefined ( )
139143 } )
140144} )
You can’t perform that action at this time.
0 commit comments