@@ -48,7 +48,9 @@ export default Component.extend({
48
48
if ( ! this . get ( 'filterData.showDeprecated' ) ) {
49
49
items = items . filter ( item => item . deprecated !== true ) ;
50
50
}
51
- return uniq ( sortBy ( items , 'name' ) , true , ( item => item . name ) ) ;
51
+
52
+ let sortedUniqueItems = uniq ( sortBy ( items , 'name' ) , true , ( item => item . name ) ) ;
53
+ return this . filterMultipleInheritance ( sortedUniqueItems ) ;
52
54
} ,
53
55
54
56
filteredData : computed ( 'filteredMethods' , 'filteredProperties' , 'filteredEvents' , function ( ) {
@@ -57,6 +59,54 @@ export default Component.extend({
57
59
properties : this . get ( 'filteredProperties' ) ,
58
60
events : this . get ( 'filteredEvents' )
59
61
} ;
60
- } )
62
+ } ) ,
61
63
62
- } ) ;
64
+ /**
65
+ * Returns an array where duplicate methods (by name) are removed.
66
+ * The docs for the nearest inheritance are typically more helpful to users,
67
+ * so in cases of duplicates, "more local" is preferred.
68
+ * Without this, multiple entries for some methods will show up.
69
+ * @method filterMultipleInheritance
70
+ */
71
+ filterMultipleInheritance ( items ) {
72
+ let dedupedArray = [ ] ;
73
+ for ( let i = 0 ; i < items . length ; i ++ ) {
74
+ let currentItem = items [ i ] ;
75
+ if ( i === items . length - 1 ) {
76
+ // if it's the last item, keep it
77
+ dedupedArray . push ( currentItem ) ;
78
+ } else {
79
+ let nextItem = items [ i + 1 ] ;
80
+ if ( currentItem . name === nextItem . name ) {
81
+ // if the method would be listed twice, find the more local documentation
82
+ let mostLocal = this . findMostLocal ( currentItem , nextItem )
83
+ dedupedArray . push ( mostLocal ) ;
84
+ i += 1 ; // skip the next item with duplicate name
85
+ } else {
86
+ dedupedArray . push ( currentItem ) ;
87
+ }
88
+ }
89
+ }
90
+ return dedupedArray ;
91
+ } ,
92
+ /**
93
+ * Returns whichever item is most local.
94
+ * What is "most local" is determined by looking at the file path for the
95
+ * method, the file path for the class being viewed, and the parent if needed.
96
+ * @method findMostLocal
97
+ */
98
+ findMostLocal ( currentItem , nextItem ) {
99
+ let currentScope = this . get ( 'model.file' ) ;
100
+ let parentClassScope = this . get ( 'model.parentClass.file' ) ;
101
+ if ( currentScope === currentItem . file ) {
102
+ // if the item belongs to the class, keep it
103
+ return currentItem ;
104
+ } else if ( parentClassScope === currentItem . file ) {
105
+ // or if the item belongs to the parent class, keep it
106
+ return currentItem ;
107
+ } else {
108
+ // otherwise, the next item must be "more local"
109
+ return nextItem ;
110
+ }
111
+ }
112
+ } )
0 commit comments