File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
test/unit/features/global-api Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -115,24 +115,27 @@ export function resolveConstructorOptions (Ctor: Class<Component>) {
115115function resolveModifiedOptions ( Ctor : Class < Component > ) : ?Object {
116116 let modified
117117 const latest = Ctor . options
118+ const extended = Ctor . extendOptions
118119 const sealed = Ctor . sealedOptions
119120 for ( const key in latest ) {
120121 if ( latest [ key ] !== sealed [ key ] ) {
121122 if ( ! modified ) modified = { }
122- modified [ key ] = dedupe ( latest [ key ] , sealed [ key ] )
123+ modified [ key ] = dedupe ( latest [ key ] , extended [ key ] , sealed [ key ] )
123124 }
124125 }
125126 return modified
126127}
127128
128- function dedupe ( latest , sealed ) {
129+ function dedupe ( latest , extended , sealed ) {
129130 // compare latest and sealed to ensure lifecycle hooks won't be duplicated
130131 // between merges
131132 if ( Array . isArray ( latest ) ) {
132133 const res = [ ]
133134 sealed = Array . isArray ( sealed ) ? sealed : [ sealed ]
135+ extended = Array . isArray ( extended ) ? extended : [ extended ]
134136 for ( let i = 0 ; i < latest . length ; i ++ ) {
135- if ( sealed . indexOf ( latest [ i ] ) < 0 ) {
137+ // push original options and not sealed options to exclude duplicated options
138+ if ( extended . indexOf ( latest [ i ] ) >= 0 || sealed . indexOf ( latest [ i ] ) < 0 ) {
136139 res . push ( latest [ i ] )
137140 }
138141 }
Original file line number Diff line number Diff line change @@ -141,4 +141,25 @@ describe('Global API: mixin', () => {
141141 } )
142142 expect ( spy ) . toHaveBeenCalledWith ( 'hello' )
143143 } )
144+
145+ // vue-class-component#87
146+ it ( 'should not drop original lifecycle hooks' , ( ) => {
147+ const base = jasmine . createSpy ( 'base' )
148+
149+ const Base = Vue . extend ( {
150+ beforeCreate : base
151+ } )
152+
153+ const injected = jasmine . createSpy ( 'injected' )
154+
155+ // inject a function
156+ Base . options . beforeCreate = Base . options . beforeCreate . concat ( injected )
157+
158+ Vue . mixin ( { } )
159+
160+ new Base ( { } )
161+
162+ expect ( base ) . toHaveBeenCalled ( )
163+ expect ( injected ) . toHaveBeenCalled ( )
164+ } )
144165} )
You can’t perform that action at this time.
0 commit comments