Skip to content
Snippets Groups Projects
Commit c41cd563 authored by Jack Reed's avatar Jack Reed
Browse files

Setup cached manifest selector that is shared between component instances

parent b0626e9d
No related branches found
No related tags found
No related merge requests found
......@@ -80,6 +80,12 @@ describe('getManifestoInstance', () => {
const received = getManifestoInstance(state, { manifestId: 'x' });
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()', () => {
......
import { createSelector } from 'reselect';
import createCachedSelector from 're-reselect';
import manifesto, { LanguageMap } from 'manifesto.js';
import ManifestoCanvas from '../../lib/ManifestoCanvas';
......@@ -18,13 +19,20 @@ export function getManifest(state, { manifestId, windowId }) {
}
/** Instantiate a manifesto instance */
export const getManifestoInstance = createSelector(
[
export const getManifestoInstance = createCachedSelector(
getManifest,
getLocale,
],
(manifest, locale) => manifest
&& 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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment