Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions client/lib/create-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,26 @@ export default function createSelector(
getDependants = DEFAULT_GET_DEPENDANTS,
getCacheKey = DEFAULT_GET_CACHE_KEY
) {
const memoizedSelector = memoize( selector, getCacheKey );
let lastDependants;
const cache = new Map();
const dependants = new Map();

if ( Array.isArray( getDependants ) ) {
getDependants = makeSelectorFromArray( getDependants );
}

return Object.assign(
function( state, ...args ) {
let currentDependants = getDependants( state, ...args );
return ( ...args ) => {
const cacheKey = getCacheKey( ...args );
const lastDependants = dependants.get( cacheKey );
let currentDependants = getDependants( ...args );
if ( ! Array.isArray( currentDependants ) ) {
currentDependants = [ currentDependants ];
}

if ( lastDependants && ! shallowEqual( currentDependants, lastDependants ) ) {
memoizedSelector.cache.clear();
if ( ! lastDependants || ! shallowEqual( currentDependants, lastDependants ) ) {
cache.set( cacheKey, selector( ...args ) );
dependants.set( cacheKey, currentDependants );
}

lastDependants = currentDependants;

return memoizedSelector( state, ...args );
},
{ memoizedSelector }
);
return cache.get( cacheKey );
};
}
3 changes: 2 additions & 1 deletion client/state/stats/lists/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* External dependencies
*/

import deterministicStringify from 'json-stable-stringify';
import {
sortBy,
toPairs,
Expand Down Expand Up @@ -139,7 +140,7 @@ export function buildExportArray( data, parent = null ) {
* @return {String} Serialized stats query
*/
export function getSerializedStatsQuery( query = {} ) {
return JSON.stringify( sortBy( toPairs( query ), pair => pair[ 0 ] ) );
return deterministicStringify( query );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. this wasn't necessary for this PR but it was in my stash

}

/**
Expand Down