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

Get rid of a function as an input to a selector

parent 061ceafa
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,16 @@ export const getCanvasLayers = createSelector( ...@@ -23,6 +23,16 @@ export const getCanvasLayers = createSelector(
}, },
); );
const EMPTY_ARRAY = Object.freeze([]);
export const getLayersForWindow = createSelector(
[
state => miradorSlice(state).layers,
(state, { windowId }) => windowId,
],
(layers, windowId) => (layers ? (layers[windowId] || EMPTY_ARRAY) : EMPTY_ARRAY),
);
/** /**
* Get the layer state for a particular canvas. * Get the layer state for a particular canvas.
* @param {object} state * @param {object} state
...@@ -31,11 +41,10 @@ export const getCanvasLayers = createSelector( ...@@ -31,11 +41,10 @@ export const getCanvasLayers = createSelector(
*/ */
export const getLayers = createSelector( export const getLayers = createSelector(
[ [
state => miradorSlice(state).layers || {}, getLayersForWindow,
(state, { windowId }) => windowId,
(state, { canvasId }) => canvasId, (state, { canvasId }) => canvasId,
], ],
(layers, windowId, canvasId) => (layers[windowId] || {})[canvasId], (layers, canvasId) => layers[canvasId],
); );
/** /**
...@@ -80,11 +89,11 @@ export const getSortedLayers = createSelector( ...@@ -80,11 +89,11 @@ export const getSortedLayers = createSelector(
export const getLayersForVisibleCanvases = createSelector( export const getLayersForVisibleCanvases = createSelector(
[ [
getVisibleCanvasIds, getVisibleCanvasIds,
(state, { windowId }) => (canvasId => getLayers(state, { canvasId, windowId })), getLayersForWindow,
], ],
(canvasIds, getLayersForCanvas) => ( (canvasIds, layers) => (
canvasIds.reduce((acc, canvasId) => { canvasIds.reduce((acc, canvasId) => {
acc[canvasId] = getLayersForCanvas(canvasId); acc[canvasId] = layers[canvasId];
return acc; return acc;
}, {}) }, {})
), ),
......
...@@ -12,8 +12,6 @@ import { getSequenceViewingDirection } from './sequences'; ...@@ -12,8 +12,6 @@ import { getSequenceViewingDirection } from './sequences';
* @return {object} * @return {object}
*/ */
export const getCurrentCanvasWorld = createSelector( export const getCurrentCanvasWorld = createSelector(
getVisibleCanvases, [getVisibleCanvases, getLayersForVisibleCanvases, getSequenceViewingDirection],
getLayersForVisibleCanvases,
getSequenceViewingDirection,
(canvases, layers, viewingDirection) => new CanvasWorld(canvases, layers, viewingDirection), (canvases, layers, viewingDirection) => new CanvasWorld(canvases, layers, viewingDirection),
); );
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment