@@ -127,16 +127,16 @@ function sortByCustom (properties, customOrder) {
127
127
function sortByConvention ( sortBy ) {
128
128
let sorts = sortBy . slice ( 0 )
129
129
let propSort = sorts . shift ( )
130
- let property = t . isArrayLike ( propSort ) && propSort . shift ( ) || undefined
131
- let sort = t . isArrayLike ( propSort ) && propSort . shift ( ) || 'asc'
130
+ let property = t . isArrayLike ( propSort ) && propSort [ 0 ] || undefined
131
+ let sort = t . isArrayLike ( propSort ) && propSort [ 1 ] || 'asc'
132
132
133
133
return function sorter ( a , b ) {
134
134
// Sort asc initially, then invert the result if a desc has been requested
135
-
136
135
let result
137
136
const x = a [ property ]
138
137
const y = b [ property ]
139
138
let currentSort = sort
139
+ let recurse
140
140
141
141
// Perform the initial asc sort
142
142
if ( x === null && y === null ) {
@@ -151,21 +151,27 @@ function sortByConvention (sortBy) {
151
151
result = x < y ? - 1 : x > y ? 1 : 0
152
152
}
153
153
154
- // Prepare the for the next call to this sorting function
155
- if ( ! ( ( result === 0 ) && ( sorts . length ) ) ) {
154
+ // Reset this sorting function and parent, unless we have an equal
155
+ // result and there are more sorts still to perform, in which case
156
+ // move on to the next one.
157
+ if ( result === 0 && sorts . length ) {
158
+ recurse = true
159
+ } else {
160
+ recurse = false
156
161
sorts = sortBy . slice ( 0 )
157
162
}
158
- propSort = sorts . shift ( )
159
- property = t . isArrayLike ( propSort ) && propSort . shift ( ) || undefined
160
- sort = t . isArrayLike ( propSort ) && propSort . shift ( ) || 'asc'
161
163
164
+ propSort = sorts . shift ( )
165
+ property = t . isArrayLike ( propSort ) && propSort [ 0 ] || undefined
166
+ sort = t . isArrayLike ( propSort ) && propSort [ 1 ] || 'asc'
167
+
162
168
// Present the result
163
- if ( ( result === 0 ) && ( sorts . length ) ) {
169
+ if ( recurse ) {
164
170
return sorter ( a , b )
165
171
} else if ( ( result === 0 ) || ( currentSort === 'asc' ) ) {
166
172
return result
167
173
} else {
168
- return result *= - 1
174
+ return result * - 1
169
175
}
170
176
}
171
177
}
0 commit comments