Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of a function as an input to a selector #3866

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/state/selectors/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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],
);

/**
Expand Down Expand Up @@ -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;
}, {})
),
Expand Down
4 changes: 1 addition & 3 deletions src/state/selectors/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);