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(
},
);
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.
* @param {object} state
......@@ -31,11 +41,10 @@ export const getCanvasLayers = createSelector(
*/
export const getLayers = createSelector(
[
state => miradorSlice(state).layers || {},
(state, { windowId }) => windowId,
getLayersForWindow,
(state, { canvasId }) => canvasId,
],
(layers, windowId, canvasId) => (layers[windowId] || {})[canvasId],
(layers, canvasId) => layers[canvasId],
);
/**
......@@ -80,11 +89,11 @@ export const getSortedLayers = createSelector(
export const getLayersForVisibleCanvases = createSelector(
[
getVisibleCanvasIds,
(state, { windowId }) => (canvasId => getLayers(state, { canvasId, windowId })),
getLayersForWindow,
],
(canvasIds, getLayersForCanvas) => (
(canvasIds, layers) => (
canvasIds.reduce((acc, canvasId) => {
acc[canvasId] = getLayersForCanvas(canvasId);
acc[canvasId] = layers[canvasId];
return acc;
}, {})
),
......
......@@ -12,8 +12,6 @@ import { getSequenceViewingDirection } from './sequences';
* @return {object}
*/
export const getCurrentCanvasWorld = createSelector(
getVisibleCanvases,
getLayersForVisibleCanvases,
getSequenceViewingDirection,
[getVisibleCanvases, getLayersForVisibleCanvases, getSequenceViewingDirection],
(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