Skip to content
Snippets Groups Projects
Unverified Commit 3c62f214 authored by Jessie Keck's avatar Jessie Keck Committed by GitHub
Browse files

Merge pull request #2920 from ProjectMirador/perf-issues

Setup cached manifest selector that is shared between component insta…
parents 0f7e6f6b c41cd563
No related branches found
No related tags found
No related merge requests found
...@@ -81,6 +81,12 @@ describe('getManifestoInstance', () => { ...@@ -81,6 +81,12 @@ describe('getManifestoInstance', () => {
const received = getManifestoInstance(state, { manifestId: 'x' }); const received = getManifestoInstance(state, { manifestId: 'x' });
expect(received.id).toEqual('http://iiif.io/api/presentation/2.1/example/fixtures/19/manifest.json'); expect(received.id).toEqual('http://iiif.io/api/presentation/2.1/example/fixtures/19/manifest.json');
}); });
it('is cached based off of input props', () => {
const state = { manifests: { x: { json: manifestFixture019 } } };
const received = getManifestoInstance(state, { manifestId: 'x' });
expect(getManifestoInstance(state, { manifestId: 'x' })).toBe(received);
expect(getManifestoInstance(state, { manifestId: 'x', windowId: 'y' })).not.toBe(received);
});
}); });
describe('getManifestLogo()', () => { describe('getManifestLogo()', () => {
......
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import createCachedSelector from 're-reselect';
import manifesto, { LanguageMap } from 'manifesto.js'; import manifesto, { LanguageMap } from 'manifesto.js';
import ManifestoCanvas from '../../lib/ManifestoCanvas'; import ManifestoCanvas from '../../lib/ManifestoCanvas';
...@@ -18,13 +19,20 @@ export function getManifest(state, { manifestId, windowId }) { ...@@ -18,13 +19,20 @@ export function getManifest(state, { manifestId, windowId }) {
} }
/** Instantiate a manifesto instance */ /** Instantiate a manifesto instance */
export const getManifestoInstance = createSelector( export const getManifestoInstance = createCachedSelector(
[
getManifest, getManifest,
getLocale, getLocale,
],
(manifest, locale) => manifest (manifest, locale) => manifest
&& createManifestoInstance(manifest.json, locale), && createManifestoInstance(manifest.json, locale),
)(
(state, props) => [
props.manifestId,
props.windowId,
(state.companionWindows
&& state.companionWindows[props.companionWindowId]
&& state.companionWindows[props.companionWindowId].locale)
|| (state.config && state.config.language),
].join(' - '), // Cache key consisting of manifestId, windowId, and locale
); );
export const getManifestLocale = createSelector( export const getManifestLocale = createSelector(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment