@@ -60,21 +60,51 @@ export default Component.extend({
60
60
} ) ,
61
61
62
62
/**
63
- * Show the most local property if there are duplicate properties of the same name .
64
- * The docs for the nearest inheritance are typically more helpful to users.
65
- * Ember-jsonapi-docs returns a mix of inherited/local, but once sorted, the
66
- * first item in the list is "most local."
63
+ * Returns an array where duplicate methods (by name) are removed .
64
+ * The docs for the nearest inheritance are typically more helpful to users,
65
+ * so in cases of duplicates, "more local" is preferred.
66
+ * Without this, multiple entries for some methods will show up.
67
67
* @method filterMultipleInheritance
68
68
*/
69
69
filterMultipleInheritance ( items ) {
70
- return items . filter ( function ( item , index , arr ) {
71
- if ( index === 0 ) {
72
- return true ;
73
- } else if ( item . name === arr [ index - 1 ] . name ) {
74
- return false ;
70
+ let dedupedArray = [ ] ;
71
+ for ( let i = 0 ; i < items . length ; i ++ ) {
72
+ let currentItem = items [ i ] ;
73
+ if ( i === items . length - 1 ) {
74
+ // if it's the last item, keep it
75
+ dedupedArray . push ( currentItem ) ;
75
76
} else {
76
- return true ;
77
+ let nextItem = items [ i + 1 ] ;
78
+ if ( currentItem . name === nextItem . name ) {
79
+ // if the method would be listed twice, find the more local documentation
80
+ let mostLocal = this . findMostLocal ( currentItem , nextItem )
81
+ dedupedArray . push ( mostLocal ) ;
82
+ i += 1 ; // skip the next item with duplicate name
83
+ } else {
84
+ dedupedArray . push ( currentItem ) ;
85
+ }
77
86
}
78
- } )
87
+ }
88
+ return dedupedArray ;
89
+ } ,
90
+ /**
91
+ * Returns whichever item is most local.
92
+ * What is "most local" is determined by looking at the file path for the
93
+ * method, the file path for the class being viewed, and the parent if needed.
94
+ * @method findMostLocal
95
+ */
96
+ findMostLocal ( currentItem , nextItem ) {
97
+ let currentScope = this . get ( 'model.file' ) ;
98
+ let parentClassScope = this . get ( 'model.parentClass.file' ) ;
99
+ if ( currentScope === currentItem . file ) {
100
+ // if the item belongs to the class, keep it
101
+ return currentItem ;
102
+ } else if ( parentClassScope === currentItem . file ) {
103
+ // or if the item belongs to the parent class, keep it
104
+ return currentItem ;
105
+ } else {
106
+ // otherwise, the next item must be "more local"
107
+ return nextItem ;
108
+ }
79
109
}
80
110
} )
0 commit comments