Skip to content

Commit fcafc8b

Browse files
committed
second pass at duplicate properties bugfix (#276)
1 parent d7143cd commit fcafc8b

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

app/components/api-index-filter.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,51 @@ export default Component.extend({
6060
}),
6161

6262
/**
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.
6767
* @method filterMultipleInheritance
6868
*/
6969
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);
7576
} 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+
}
7786
}
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+
}
79109
}
80110
})

0 commit comments

Comments
 (0)