File tree 2 files changed +27
-3
lines changed
test/unit/features/global-api
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>) {
115
115
function resolveModifiedOptions ( Ctor : Class < Component > ) : ?Object {
116
116
let modified
117
117
const latest = Ctor . options
118
+ const extended = Ctor . extendOptions
118
119
const sealed = Ctor . sealedOptions
119
120
for ( const key in latest ) {
120
121
if ( latest [ key ] !== sealed [ key ] ) {
121
122
if ( ! modified ) modified = { }
122
- modified [ key ] = dedupe ( latest [ key ] , sealed [ key ] )
123
+ modified [ key ] = dedupe ( latest [ key ] , extended [ key ] , sealed [ key ] )
123
124
}
124
125
}
125
126
return modified
126
127
}
127
128
128
- function dedupe ( latest , sealed ) {
129
+ function dedupe ( latest , extended , sealed ) {
129
130
// compare latest and sealed to ensure lifecycle hooks won't be duplicated
130
131
// between merges
131
132
if ( Array . isArray ( latest ) ) {
132
133
const res = [ ]
133
134
sealed = Array . isArray ( sealed ) ? sealed : [ sealed ]
135
+ extended = Array . isArray ( extended ) ? extended : [ extended ]
134
136
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 ) {
136
139
res . push ( latest [ i ] )
137
140
}
138
141
}
Original file line number Diff line number Diff line change @@ -141,4 +141,25 @@ describe('Global API: mixin', () => {
141
141
} )
142
142
expect ( spy ) . toHaveBeenCalledWith ( 'hello' )
143
143
} )
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
+ } )
144
165
} )
You can’t perform that action at this time.
0 commit comments