Skip to content
Snippets Groups Projects
Commit cd635dce authored by Chris Beer's avatar Chris Beer
Browse files

Add special memoizing logic to getLocales to keep providing the same array each call

parent ab3457e6
Branches
No related tags found
No related merge requests found
import { createSelector } from 'reselect';
import { createSelector, createSelectorCreator } from 'reselect';
import manifesto, { LanguageMap } from 'manifesto.js';
import memoize from 'lodash/memoize';
import ManifestoCanvas from '../../lib/ManifestoCanvas';
/** Get the relevant manifest information */
......@@ -346,7 +347,15 @@ function getLocales(resource) {
return Object.keys(languages);
}
export const getMetadataLocales = createSelector(
/** */
const manifestHashFn = manifest => manifest && manifest.id;
// this has the potential to be an annoying memory leak, because the memoize store will grow
// unbounded.
const manifestMemoizingSelectorCreator = createSelectorCreator(memoize, manifestHashFn);
// this is specially memoized because getLocales is creating new array instances
// every time it is called.
export const getMetadataLocales = manifestMemoizingSelectorCreator(
[getManifestoInstance],
manifest => getLocales(manifest),
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment