@@ -17,11 +17,11 @@ let HAS_GLIMMER_TRACKING = false;
1717try {
1818 glimmer = Ember . __loader . require ( '@glimmer/reference' ) ;
1919 metal = Ember . __loader . require ( '@ember/-internals/metal' ) ;
20- HAS_GLIMMER_TRACKING = glimmer &&
21- glimmer . value &&
22- glimmer . validate &&
23- metal &&
24- metal . track &&
20+ HAS_GLIMMER_TRACKING = glimmer &&
21+ glimmer . value &&
22+ glimmer . validate &&
23+ metal &&
24+ metal . track &&
2525 metal . tagForProperty ;
2626} catch ( e ) {
2727 glimmer = null ;
3030
3131const keys = Object . keys || Ember . keys ;
3232
33+ /**
34+ * Add Known Ember Mixins and Classes so we can label them correctly in the inspector
35+ */
36+ const emberNames = new Map ( [
37+ [ Ember . Evented , 'Evented Mixin' ] ,
38+ [ Ember . PromiseProxyMixin , 'PromiseProxy Mixin' ] ,
39+ [ Ember . MutableArray , 'MutableArray Mixin' ] ,
40+ [ Ember . MutableEnumerable , 'MutableEnumerable Mixin' ] ,
41+ [ Ember . NativeArray , 'NativeArray Mixin' ] ,
42+ [ Ember . Observable , 'Observable Mixin' ] ,
43+ [ Ember . ControllerMixin , 'Controller Mixin' ] ,
44+ [ Ember . TargetActionSupport , 'TargetActionSupport Mixin' ] ,
45+ [ Ember . ActionHandler , 'ActionHandler Mixin' ] ,
46+ [ Ember . CoreObject , 'CoreObject' ] ,
47+ [ Ember . Object , 'EmberObject' ] ,
48+ [ Ember . Component , 'Component' ] ,
49+ ] ) ;
50+
51+ try {
52+ const Views = Ember . __loader . require ( '@ember/-internals/views' ) ;
53+ emberNames . set ( Views . ViewStateSupport , 'ViewStateSupport Mixin' ) ;
54+ emberNames . set ( Views . ViewMixin , 'View Mixin' ) ;
55+ emberNames . set ( Views . ActionSupport , 'ActionSupport Mixin' ) ;
56+ emberNames . set ( Views . ClassNamesSupport , 'ClassNamesSupport Mixin' ) ;
57+ emberNames . set ( Views . ChildViewsSupport , 'ChildViewsSupport Mixin' ) ;
58+ emberNames . set ( Views . ViewStateSupport , 'ViewStateSupport Mixin' ) ;
59+ // this one is not a Mixin, but an .extend({}), which results in a class
60+ emberNames . set ( Views . CoreView , 'CoreView' ) ;
61+ } catch ( e ) {
62+ // do nothing
63+ }
64+
65+
3366/**
3467 * Determine the type and get the value of the passed property
3568 * @param {* } object The parent object we will look for `key` on
@@ -132,7 +165,7 @@ function isMandatorySetter(descriptor) {
132165 return false ;
133166}
134167
135- function getTagTrackedProps ( tag , ownTag , level = 0 ) {
168+ function getTagTrackedProps ( tag , ownTag , level = 0 ) {
136169 const props = [ ] ;
137170 // do not include tracked properties from dependencies
138171 if ( ! tag || level > 1 ) {
@@ -179,7 +212,7 @@ export default EmberObject.extend(PortMixin, {
179212
180213 updateCurrentObject ( ) {
181214 if ( this . currentObject ) {
182- const { object, mixinDetails, objectId} = this . currentObject ;
215+ const { object, mixinDetails, objectId } = this . currentObject ;
183216 mixinDetails . forEach ( ( mixin , mixinIndex ) => {
184217 mixin . properties . forEach ( item => {
185218 if ( item . overridden ) {
@@ -193,7 +226,7 @@ export default EmberObject.extend(PortMixin, {
193226 let value = null ;
194227 let changed = false ;
195228 const values = this . objectPropertyValues [ objectId ] = this . objectPropertyValues [ objectId ] || { } ;
196- const tracked = this . trackedTags [ objectId ] = this . trackedTags [ objectId ] || { } ;
229+ const tracked = this . trackedTags [ objectId ] = this . trackedTags [ objectId ] || { } ;
197230
198231 const desc = Object . getOwnPropertyDescriptor ( object , item . name ) ;
199232 const isSetter = desc && isMandatorySetter ( desc ) ;
@@ -525,26 +558,28 @@ export default EmberObject.extend(PortMixin, {
525558 mixinDetailsForObject ( object ) {
526559 const mixins = [ ] ;
527560
528- const mixin = {
561+ const own = ownMixins ( object ) ;
562+
563+ const objectMixin = {
529564 id : guidFor ( object ) ,
530565 name : getClassName ( object ) ,
531- properties : ownProperties ( object )
566+ properties : ownProperties ( object , own )
532567 } ;
533568
534- mixins . push ( mixin ) ;
569+ mixins . push ( objectMixin ) ;
535570
536571 // insert ember mixins
537- for ( let mixin of ownMixins ( object ) ) {
538- let name = ( mixin [ Ember . NAME_KEY ] || mixin . ownerConstructor || '' ) . toString ( ) ;
572+ for ( let mixin of own ) {
573+ let name = ( mixin [ Ember . NAME_KEY ] || mixin . ownerConstructor || emberNames . get ( mixin ) || '' ) . toString ( ) ;
539574
540- if ( typeof mixin . toString === 'function' ) {
575+ if ( ! name && ( typeof mixin . toString === 'function' ) ) {
541576 try {
542577 name = mixin . toString ( ) ;
543578
544579 if ( name === '(unknown)' ) {
545580 name = '(unknown mixin)' ;
546581 }
547- } catch ( e ) {
582+ } catch ( e ) {
548583 name = '(Unable to convert Object to string)' ;
549584 }
550585 }
@@ -596,7 +631,7 @@ export default EmberObject.extend(PortMixin, {
596631 let objectId = this . retainObject ( object ) ;
597632
598633 let errorsForObject = this . get ( '_errorsFor' ) [ objectId ] = { } ;
599- const tracked = this . trackedTags [ objectId ] = this . trackedTags [ objectId ] || { } ;
634+ const tracked = this . trackedTags [ objectId ] = this . trackedTags [ objectId ] || { } ;
600635 calculateCPs ( object , mixinDetails , errorsForObject , expensiveProperties , tracked ) ;
601636
602637 this . currentObject = { object, mixinDetails, objectId } ;
@@ -629,7 +664,7 @@ export default EmberObject.extend(PortMixin, {
629664
630665function getClassName ( object ) {
631666 let name = '' ;
632- let className = object . constructor . name ;
667+ let className = emberNames . get ( object . constructor ) || object . constructor . name ;
633668
634669 if ( 'toString' in object && object . toString !== Function . prototype . toString ) {
635670 name = object . toString ( ) ;
@@ -677,10 +712,9 @@ function ownMixins(object) {
677712 return mixins ;
678713}
679714
680- function ownProperties ( object ) {
715+ function ownProperties ( object , ownMixins ) {
681716 let meta = Ember . meta ( object ) ;
682- let parentMeta = meta . parent ;
683-
717+
684718 if ( Array . isArray ( object ) ) {
685719 // slice to max 101, for performance and so that the object inspector will show a `more items` indicator above 100
686720 object = object . slice ( 0 , 101 ) ;
@@ -689,13 +723,36 @@ function ownProperties(object) {
689723 let props = Object . getOwnPropertyDescriptors ( object ) ;
690724 delete props . constructor ;
691725
726+ // meta has the correct descriptors for CPs
692727 meta . forEachDescriptors ( ( name , desc ) => {
693- // TODO: Need to add a way to get own descriptors only from meta
694- if ( ! parentMeta || ! parentMeta . peekDescriptors ( name ) ) {
728+ // only for own properties
729+ if ( props [ name ] ) {
695730 props [ name ] = desc ;
696731 }
697732 } ) ;
698733
734+ // remove properties set by mixins
735+ // especially for Object.extend(mixin1, mixin2), where a new class is created which holds the merged properties
736+ // if all properties are removed, it will be marked as useless mixin and will not be shown
737+ ownMixins . forEach ( ( m ) => {
738+ if ( m . mixins ) {
739+ m . mixins . forEach ( ( mix ) => {
740+ Object . keys ( mix . properties || { } ) . forEach ( ( k ) => {
741+ const pDesc = Object . getOwnPropertyDescriptor ( mix . properties , k ) ;
742+ if ( pDesc && props [ k ] && pDesc . get && pDesc . get === props [ k ] . get ) {
743+ delete props [ k ] ;
744+ }
745+ if ( pDesc && props [ k ] && 'value' in pDesc && pDesc . value === props [ k ] . value ) {
746+ delete props [ k ] ;
747+ }
748+ if ( pDesc && props [ k ] && pDesc . _getter === props [ k ] . _getter ) {
749+ delete props [ k ] ;
750+ }
751+ } )
752+ } )
753+ }
754+ } ) ;
755+
699756 Object . keys ( props ) . forEach ( k => {
700757 if ( typeof props [ k ] . value === 'function' ) {
701758 return ;
@@ -910,7 +967,7 @@ function calculateCPs(object, mixinDetails, errorsForObject, expensiveProperties
910967 tagInfo . revision = glimmer . value ( object , item . name ) ;
911968 item . dependentKeys = getTrackedDependencies ( object , item . name , tagInfo . tag ) ;
912969 } else {
913- value = calculateCP ( object , item . name , errorsForObject ) ;
970+ value = calculateCP ( object , item . name , errorsForObject ) ;
914971 }
915972 if ( ! value || ! ( value instanceof CalculateCPError ) ) {
916973 item . value = inspectValue ( object , item . name , value ) ;
@@ -1080,13 +1137,13 @@ function calculateCP(object, property, errorsForObject) {
10801137 return object . objectAt ( property ) ;
10811138 }
10821139 return get ( object , property ) ;
1083- } catch ( error ) {
1140+ } catch ( error ) {
10841141 errorsForObject [ property ] = { property, error } ;
10851142 return new CalculateCPError ( ) ;
10861143 }
10871144}
10881145
1089- function CalculateCPError ( ) { }
1146+ function CalculateCPError ( ) { }
10901147
10911148function errorsToSend ( errors ) {
10921149 return toArray ( errors ) . map ( error => ( { property : error . property } ) ) ;
0 commit comments