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
Branches
Tags
No related merge requests found
...@@ -80,6 +80,12 @@ describe('getManifestoInstance', () => { ...@@ -80,6 +80,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 to comment