Loda sh порядок, не упорядочивая массив - PullRequest
0 голосов
/ 17 марта 2020

Функциональная часть реагирующего приложения, использующего приставку. Я реализовал фильтрацию и сортировку для каталога товаров в редукторном селекторе. OrderBy не возвращает отсортированный массив. Селектор вызывает функцию заказа; однако возвращенные результаты не отсортированы.

export const _sortingDestinations = (destinations,properties ) =>
{

    window.destinations = destinations
    window.orderBy = _.orderBy

    const sorted = _.orderBy( destinations,[ 'name' ],[  'asc' ] )
    console.log("Original", destinations)
    console.log("sorted", sorted)
    return  sorted

}
//This function is called by the following redux selector

const getCatalogList = state => state.catalog.list
const getFilter = state => state.filter
const getSort = state => state.sort

export default createSelector(
    getCatalogList,
    getFilter,
    getSort,
    (items,filter,sort) => _sortingDestinations(_.filter( 
        _.map(items, o => WindPoint(o,filter)),
        ( o ) => DestinationFilter( o,filter ) ),sort)
)

Журналы консоли:

Original:
0: {name: "Beauduc", country: "France", airport: "MRS", youtubeLink: Array(2), _rawDescription: null, …}
1: {name: "Cocos (Keeling) Islands", country: "Australia", airport: "CCK", youtubeLink: Array(4), _rawDescription: null, …}
2: {name: "Fuerteventura", country: "Spain", airport: "FUE", youtubeLink: Array(4), _rawDescription: null, …}
3: {name: "Moorea", country: "French Polynesia", airport: "MOZ", youtubeLink: Array(4), _rawDescription: null, …}
4: {name: "Rarotonga", country: "Cook Islands", airport: "RAR", youtubeLink: Array(2), _rawDescription: null, …}
5: {name: "Roatan", country: "Honduras", airport: "RTB", youtubeLink: Array(4), _rawDescription: null, …}
6: {name: "Taveuni Island", country: "Fiji", airport: "TVU", youtubeLink: Array(2), _rawDescription: null, …}
7: {name: "Vanuatu", country: "Fiji", airport: "VLI", youtubeLink: null, _rawDescription: null, …}
8: {name: "Whitsunday Islands", country: "Australia", airport: "HTI", yout

Sorted:
0: {name: "Roatan", country: "Honduras", airport: "RTB", youtubeLink: Array(4), _rawDescription: null, …}
1: {name: "Taveuni Island", country: "Fiji", airport: "TVU", youtubeLink: Array(2), _rawDescription: null, …}
2: {name: "Fuerteventura", country: "Spain", airport: "FUE", youtubeLink: Array(4), _rawDescription: null, …}
3: {name: "Beauduc", country: "France", airport: "MRS", youtubeLink: Array(2), _rawDescription: null, …}
4: {name: "Whitsunday Islands", country: "Australia", airport: "HTI", youtubeLink: Array(2), _rawDescription: null, …}
5: {name: "Vanuatu", country: "Fiji", airport: "VLI", youtubeLink: null, _rawDescription: null, …}
6: {name: "Rarotonga", country: "Cook Islands", airport: "RAR", youtubeLink: Array(2), _rawDescription: null, …}
7: {name: "Moorea", country: "French Polynesia", airport: "MOZ", youtubeLink: Array(4), _rawDescription: null, …}
8: {name: "Cocos (Keeling) Islands", country: "Australia", airport: "CCK"

Если я запускаю тот же код в консоли Chrome, я получаю желаемые результаты:

orderBy(destinations,['name'],['asc'])
0: {name: "Beauduc", country: "France", airport: "MRS", youtubeLink: Array(2), _rawDescription: null, …}
1: {name: "Cocos (Keeling) Islands", country: "Australia", airport: "CCK", youtubeLink: Array(4), _rawDescription: null, …}
2: {name: "Fuerteventura", country: "Spain", airport: "FUE", youtubeLink: Array(4), _rawDescription: null, …}
3: {name: "Moorea", country: "French Polynesia", airport: "MOZ", youtubeLink: Array(4), _rawDescription: null, …}
4: {name: "Rarotonga", country: "Cook Islands", airport: "RAR", youtubeLink: Array(2), _rawDescription: null, …}
5: {name: "Roatan", country: "Honduras", airport: "RTB", youtubeLink: Array(4), _rawDescription: null, …}
6: {name: "Taveuni Island", country: "Fiji", airport: "TVU", youtubeLink: Array(2), _rawDescription: null, …}
7: {name: "Vanuatu", country: "Fiji", airport: "VLI", youtubeLink: null, _rawDescription: null, …}
8: {name: "Whitsunday Islands", country: "Australia", airport: "HTI", youtu
...