diff --git a/src/state/selectors/manifests.js b/src/state/selectors/manifests.js index 28a96ade92d08ccb11541dac5800f386f3249cc6..095cd40fe54cbad8b4eddfbfbdd4ed021316cba2 100644 --- a/src/state/selectors/manifests.js +++ b/src/state/selectors/manifests.js @@ -1,5 +1,6 @@ -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), );