@@ -30,6 +30,13 @@ const SORT_ORDER = {
30
30
none : 2
31
31
} ;
32
32
33
+ function find ( arr , cb ) {
34
+ for ( let i = 0 ; i < arr . length ; i ++ ) {
35
+ if ( cb ( arr [ i ] ) ) return arr [ i ] ;
36
+ }
37
+ }
38
+
39
+
33
40
export class Table extends React . Component {
34
41
static propTypes = {
35
42
bodyRowClassName : PropTypes . string ,
@@ -44,7 +51,7 @@ export class Table extends React.Component {
44
51
super ( props , context ) ;
45
52
const { columns, defaultSort} = props ;
46
53
47
- const sortColumn = columns . find ( ( { sortable, attribute} ) => {
54
+ const sortColumn = find ( columns , ( { sortable, attribute} ) => {
48
55
return defaultSort ? attribute === defaultSort : sortable ;
49
56
} ) ;
50
57
this . state = { sortColumn, sortOrder : SORT_ORDER . asc } ;
@@ -55,7 +62,7 @@ export class Table extends React.Component {
55
62
56
63
componentWillReceiveProps ( { columns, defaultSort} ) {
57
64
if ( columns ) {
58
- const sortColumn = columns . find ( ( { sortable, attribute} ) => {
65
+ const sortColumn = find ( columns , ( { sortable, attribute} ) => {
59
66
return defaultSort ? attribute === defaultSort : sortable ;
60
67
} ) ;
61
68
this . setState ( { sortColumn, sortOrder : SORT_ORDER . asc } ) ;
@@ -190,7 +197,7 @@ export class FlexTable extends Table {
190
197
super ( props , context ) ;
191
198
const { columns, defaultSort} = props ;
192
199
193
- const sortColumn = columns . find ( ( { sortable, attribute} ) => {
200
+ const sortColumn = find ( columns , ( { sortable, attribute} ) => {
194
201
return defaultSort ? attribute === defaultSort : sortable ;
195
202
} ) ;
196
203
0 commit comments