@@ -2,7 +2,7 @@ import { BackendContext } from '@vue-devtools/app-backend-api'
2
2
import { getInstanceName , getUniqueComponentId } from './util'
3
3
import { camelize , get , set } from '@vue-devtools/shared-utils'
4
4
import SharedData from '@vue-devtools/shared-utils/lib/shared-data'
5
- import { HookPayloads , Hooks , InspectedComponentData } from '@vue/devtools-api'
5
+ import { ComponentInstance , HookPayloads , Hooks , InspectedComponentData } from '@vue/devtools-api'
6
6
import { returnError } from '../util'
7
7
8
8
/**
@@ -18,13 +18,14 @@ export function getInstanceDetails (instance: any, ctx: BackendContext): Inspect
18
18
}
19
19
20
20
function getInstanceState ( instance ) {
21
+ const mergedType = resolveMergedOptions ( instance )
21
22
return processProps ( instance ) . concat (
22
23
processState ( instance ) ,
23
24
processSetupState ( instance ) ,
24
- processComputed ( instance ) ,
25
+ processComputed ( instance , mergedType ) ,
25
26
processAttrs ( instance ) ,
26
27
processProvide ( instance ) ,
27
- processInject ( instance ) ,
28
+ processInject ( instance , mergedType ) ,
28
29
processRefs ( instance )
29
30
)
30
31
}
@@ -173,8 +174,8 @@ function getSetupStateInfo (raw: any) {
173
174
* @param {Vue } instance
174
175
* @return {Array }
175
176
*/
176
- function processComputed ( instance ) {
177
- const type = instance . type
177
+ function processComputed ( instance , mergedType ) {
178
+ const type = mergedType
178
179
const computed = [ ]
179
180
const defs = type . computed || { }
180
181
// use for...in here because if 'computed' is not defined
@@ -215,17 +216,17 @@ function processProvide (instance) {
215
216
} ) )
216
217
}
217
218
218
- function processInject ( instance ) {
219
- if ( ! instance . type || ! instance . type . inject ) return [ ]
219
+ function processInject ( instance , mergedType ) {
220
+ if ( ! mergedType ? .inject ) return [ ]
220
221
let keys = [ ]
221
- if ( Array . isArray ( instance . type . inject ) ) {
222
- keys = instance . type . inject . map ( key => ( {
222
+ if ( Array . isArray ( mergedType . inject ) ) {
223
+ keys = mergedType . inject . map ( key => ( {
223
224
key,
224
225
originalKey : key
225
226
} ) )
226
227
} else {
227
- keys = Object . keys ( instance . type . inject ) . map ( key => {
228
- const value = instance . type . inject [ key ]
228
+ keys = Object . keys ( mergedType . inject ) . map ( key => {
229
+ const value = mergedType . inject [ key ]
229
230
let originalKey
230
231
if ( typeof value === 'string' ) {
231
232
originalKey = value
@@ -323,3 +324,45 @@ export function getCustomInstanceDetails (instance) {
323
324
}
324
325
}
325
326
}
327
+
328
+ function resolveMergedOptions (
329
+ instance : ComponentInstance
330
+ ) {
331
+ const raw = instance . type
332
+ const { mixins, extends : extendsOptions } = raw
333
+ const globalMixins = instance . appContext . mixins
334
+ if ( ! globalMixins . length && ! mixins && ! extendsOptions ) return raw
335
+ const options = { }
336
+ globalMixins . forEach ( m => mergeOptions ( options , m , instance ) )
337
+ mergeOptions ( options , raw , instance )
338
+ return options
339
+ }
340
+
341
+ function mergeOptions (
342
+ to : any ,
343
+ from : any ,
344
+ instance : ComponentInstance
345
+ ) {
346
+ if ( typeof from === 'function' ) {
347
+ from = from . options
348
+ }
349
+
350
+ const { mixins, extends : extendsOptions } = from
351
+
352
+ extendsOptions && mergeOptions ( to , extendsOptions , instance )
353
+ mixins &&
354
+ mixins . forEach ( ( m ) =>
355
+ mergeOptions ( to , m , instance )
356
+ )
357
+
358
+ for ( const key of [ 'computed' , 'inject' ] ) {
359
+ if ( Object . prototype . hasOwnProperty . call ( from , key ) ) {
360
+ if ( ! to [ key ] ) {
361
+ to [ key ] = from [ key ]
362
+ } else {
363
+ Object . assign ( to [ key ] , from [ key ] )
364
+ }
365
+ }
366
+ }
367
+ return to
368
+ }
0 commit comments