@@ -2,60 +2,78 @@ import { computed } from '@ember/object';
2
2
import Component from '@ember/component' ;
3
3
import sortBy from 'lodash.sortby' ;
4
4
5
- const filterDataComputedParams = 'filterData.{showInherited,showProtected,showPrivate,showDeprecated}' ;
5
+ const filterDataComputedParams =
6
+ 'filterData.{showInherited,showProtected,showPrivate,showDeprecated}' ;
6
7
7
8
export default Component . extend ( {
8
9
classNames : [ 'api-index-filter' ] ,
9
10
10
- filteredMethods : computed ( 'model.methods.[]' , filterDataComputedParams ,
11
- function ( ) {
11
+ filteredMethods : computed (
12
+ 'model.methods.[]' ,
13
+ filterDataComputedParams ,
14
+ function ( ) {
12
15
return this . filterItems ( 'methods' ) ;
13
- } ) ,
16
+ }
17
+ ) ,
14
18
15
- filteredEvents : computed ( 'model.events.[]' , filterDataComputedParams ,
16
- function ( ) {
19
+ filteredEvents : computed (
20
+ 'model.events.[]' ,
21
+ filterDataComputedParams ,
22
+ function ( ) {
17
23
return this . filterItems ( 'events' ) ;
18
- } ) ,
24
+ }
25
+ ) ,
19
26
20
- filteredProperties : computed ( 'model.properties.[]' , filterDataComputedParams ,
21
- function ( ) {
27
+ filteredProperties : computed (
28
+ 'model.properties.[]' ,
29
+ filterDataComputedParams ,
30
+ function ( ) {
22
31
return this . filterItems ( 'properties' ) ;
23
- } ) ,
32
+ }
33
+ ) ,
24
34
25
35
filterItems ( itemType ) {
26
- let items = this . getWithDefault ( `model.${ itemType } ` , [ ] ) ;
36
+ let items =
37
+ this . get ( `model.${ itemType } ` ) === undefined
38
+ ? [ ]
39
+ : this . get ( `model.${ itemType } ` ) ;
27
40
if ( ! this . get ( 'filterData.showInherited' ) ) {
28
- items = items . filter ( item => item . inherited !== true ) ;
41
+ items = items . filter ( ( item ) => item . inherited !== true ) ;
29
42
}
30
43
if ( ! this . get ( 'filterData.showProtected' ) ) {
31
- items = items . filter ( item => item . access !== 'protected' ) ;
44
+ items = items . filter ( ( item ) => item . access !== 'protected' ) ;
32
45
}
33
46
if ( ! this . get ( 'filterData.showPrivate' ) ) {
34
- items = items . filter ( item => item . access !== 'private' ) ;
47
+ items = items . filter ( ( item ) => item . access !== 'private' ) ;
35
48
}
36
49
if ( ! this . get ( 'filterData.showDeprecated' ) ) {
37
- items = items . filter ( item => item . deprecated !== true ) ;
50
+ items = items . filter ( ( item ) => item . deprecated !== true ) ;
38
51
}
39
52
40
- let sortedItems = sortBy ( items , ( item => item . name ) ) ;
53
+ let sortedItems = sortBy ( items , ( item ) => item . name ) ;
41
54
return this . filterMultipleInheritance ( sortedItems ) ;
42
55
} ,
43
56
44
- filteredData : computed ( 'filteredMethods' , 'filteredProperties' , 'filteredEvents' , function ( ) {
45
- return {
46
- methods : this . filteredMethods ,
47
- properties : this . filteredProperties ,
48
- events : this . filteredEvents
49
- } ;
50
- } ) ,
57
+ filteredData : computed (
58
+ 'filteredMethods' ,
59
+ 'filteredProperties' ,
60
+ 'filteredEvents' ,
61
+ function ( ) {
62
+ return {
63
+ methods : this . filteredMethods ,
64
+ properties : this . filteredProperties ,
65
+ events : this . filteredEvents ,
66
+ } ;
67
+ }
68
+ ) ,
51
69
52
70
/**
53
- * Returns an array where duplicate methods (by name) are removed.
54
- * The docs for the nearest inheritance are typically more helpful to users,
55
- * so in cases of duplicates, "more local" is preferred.
56
- * Without this, multiple entries for some methods will show up.
57
- * @method filterMultipleInheritance
58
- */
71
+ * Returns an array where duplicate methods (by name) are removed.
72
+ * The docs for the nearest inheritance are typically more helpful to users,
73
+ * so in cases of duplicates, "more local" is preferred.
74
+ * Without this, multiple entries for some methods will show up.
75
+ * @method filterMultipleInheritance
76
+ */
59
77
filterMultipleInheritance ( items ) {
60
78
let dedupedArray = [ ] ;
61
79
for ( let i = 0 ; i < items . length ; i ++ ) {
@@ -67,7 +85,7 @@ export default Component.extend({
67
85
let nextItem = items [ i + 1 ] ;
68
86
if ( currentItem . name === nextItem . name ) {
69
87
// if the method would be listed twice, find the more local documentation
70
- let mostLocal = this . findMostLocal ( currentItem , nextItem )
88
+ let mostLocal = this . findMostLocal ( currentItem , nextItem ) ;
71
89
dedupedArray . push ( mostLocal ) ;
72
90
i += 1 ; // skip the next item with duplicate name
73
91
} else {
@@ -78,11 +96,11 @@ export default Component.extend({
78
96
return dedupedArray ;
79
97
} ,
80
98
/**
81
- * Returns whichever item is most local.
82
- * What is "most local" is determined by looking at the file path for the
83
- * method, the file path for the class being viewed, and the parent if needed.
84
- * @method findMostLocal
85
- */
99
+ * Returns whichever item is most local.
100
+ * What is "most local" is determined by looking at the file path for the
101
+ * method, the file path for the class being viewed, and the parent if needed.
102
+ * @method findMostLocal
103
+ */
86
104
findMostLocal ( currentItem , nextItem ) {
87
105
let currentScope = this . get ( 'model.file' ) ;
88
106
let parentClassScope = this . get ( 'model.parentClass.file' ) ;
@@ -96,5 +114,5 @@ export default Component.extend({
96
114
// otherwise, the next item must be "more local"
97
115
return nextItem ;
98
116
}
99
- }
100
- } )
117
+ } ,
118
+ } ) ;
0 commit comments