Skip to content
Snippets Groups Projects
Commit 300400ca authored by Mathias Maaß's avatar Mathias Maaß
Browse files

replace immutablejs by lodash

parent ba575555
No related branches found
No related tags found
No related merge requests found
import { setIn } from 'immutable';
import set from 'lodash/fp/set';
import noRangesJson from '../../fixtures/version-2/001.json';
import manifestJson from '../../fixtures/version-2/structures.json';
import presentation3Json from '../../fixtures/version-3/structures.json';
......@@ -31,7 +32,7 @@ const state = {
},
};
const expandedNodesState = setIn(state, ['companionWindows', 'cw123', 'tocNodes'], {
const expandedNodesState = set(['companionWindows', 'cw123', 'tocNodes'], {
'0-0': {
expanded: false,
},
......@@ -44,11 +45,11 @@ const expandedNodesState = setIn(state, ['companionWindows', 'cw123', 'tocNodes'
'0-1-2': {
expanded: false,
},
});
}, state);
describe('getVisibleNodeIds', () => {
const prezi3BookState = setIn(state, ['manifests', 'mID', 'json'], presentation3Json);
const prezi3State = setIn(prezi3BookState, ['windows', 'w1', 'view'], 'single');
const prezi3BookState = set(['manifests', 'mID', 'json'], presentation3Json, state);
const prezi3State = set(['windows', 'w1', 'view'], 'single', prezi3BookState);
it('contains node ids for all ranges which contain currently visible canvases, and for their parents', () => {
const visibleNodeIds = getVisibleNodeIds(state, { windowId: 'w1' });
......@@ -60,7 +61,7 @@ describe('getVisibleNodeIds', () => {
]));
expect(visibleNodeIds.length).toBe(4);
const prezi3StateForCanvas2 = setIn(prezi3State, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c2']);
const prezi3StateForCanvas2 = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c2'], prezi3State);
const prezi3visibleNodeIds = getVisibleNodeIds(prezi3StateForCanvas2, { windowId: 'w1' });
expect(prezi3visibleNodeIds).toEqual(expect.arrayContaining([
'0-0',
......@@ -70,8 +71,8 @@ describe('getVisibleNodeIds', () => {
});
it('contains node ids for ranges with currently visible canvas fragments', () => {
const prezi2XYWHFragmentBookState = setIn(state, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c3']);
const prezi2XYWHFragmentState = setIn(prezi2XYWHFragmentBookState, ['windows', 'w1', 'view'], 'single');
const prezi2XYWHFragmentBookState = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c3'], state);
const prezi2XYWHFragmentState = set(['windows', 'w1', 'view'], 'single', prezi2XYWHFragmentBookState);
const visibleNodeIdsForPrezi2 = getVisibleNodeIds(prezi2XYWHFragmentState, { windowId: 'w1' });
expect(visibleNodeIdsForPrezi2).toEqual(expect.arrayContaining([
'0-0',
......@@ -79,7 +80,7 @@ describe('getVisibleNodeIds', () => {
]));
expect(visibleNodeIdsForPrezi2.length).toBe(2);
const prezi3XYWHFragmentState = setIn(prezi3State, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c3']);
const prezi3XYWHFragmentState = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c3'], prezi3State);
const visibleNodeIdsForXYWHFragment = getVisibleNodeIds(prezi3XYWHFragmentState, { windowId: 'w1' });
expect(visibleNodeIdsForXYWHFragment).toEqual(expect.arrayContaining([
'0-0',
......@@ -87,7 +88,7 @@ describe('getVisibleNodeIds', () => {
]));
expect(visibleNodeIdsForXYWHFragment.length).toBe(2);
const prezi3TemporalFragmentState = setIn(prezi3State, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c4']);
const prezi3TemporalFragmentState = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c4'], prezi3State);
const visibleNodeIdsForTemporalFragment = getVisibleNodeIds(prezi3TemporalFragmentState, { windowId: 'w1' });
expect(visibleNodeIdsForTemporalFragment).toEqual(expect.arrayContaining([
'0-0',
......@@ -98,7 +99,7 @@ describe('getVisibleNodeIds', () => {
// This test fails as there is no support for SpecificResource in manifesto yet
it.skip('contains node ids for ranges that contain a SpecificResource based on a current canvas', () => {
const specificResourceState = setIn(prezi3State, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c5']);
const specificResourceState = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c5'], prezi3State);
const visibleNodeIds = getVisibleNodeIds(specificResourceState, { windowId: 'w1' });
expect(visibleNodeIds).toEqual(expect.arrayContaining([
'0-0',
......@@ -122,7 +123,7 @@ describe('getManuallyExpandedNodeIds', () => {
describe('getExpandedNodeIds', () => {
it('returns manually expanded node ids and visible, non collapsed branch node ids', () => {
const canvas8BookViewState = setIn(expandedNodesState, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c8', 'http://foo.test/1/canvas/c9']);
const canvas8BookViewState = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c8', 'http://foo.test/1/canvas/c9'], expandedNodesState);
const canvas8BookViewVisibleNodeIds = getExpandedNodeIds(canvas8BookViewState, { companionWindowId: 'cw123', windowId: 'w1' });
expect(canvas8BookViewVisibleNodeIds).toEqual(expect.arrayContaining([
'0-1',
......@@ -133,7 +134,7 @@ describe('getExpandedNodeIds', () => {
]));
expect(canvas8BookViewVisibleNodeIds.length).toBe(5);
const canvas8SingleViewState = setIn(canvas8BookViewState, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c8']);
const canvas8SingleViewState = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c8'], canvas8BookViewState);
const canvas8SingleViewVisibleNodeIds = getExpandedNodeIds(canvas8SingleViewState, { companionWindowId: 'cw123', windowId: 'w1' });
expect(canvas8SingleViewVisibleNodeIds).toEqual(expect.arrayContaining([
'0-1',
......@@ -143,7 +144,7 @@ describe('getExpandedNodeIds', () => {
});
it('returns a combination of manually opened and current canvas containing node ids', () => {
const canvas9State = setIn(expandedNodesState, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c9']);
const canvas9State = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c9'], expandedNodesState);
const expandedNodeIds = getExpandedNodeIds(canvas9State, { companionWindowId: 'cw123', windowId: 'w1' });
expect(expandedNodeIds).toEqual(expect.arrayContaining([
'0-1',
......@@ -156,7 +157,7 @@ describe('getExpandedNodeIds', () => {
});
it('does not contain ids of nodes whos descendants do not contain currently visible canvases', () => {
const canvas13State = setIn(state, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c13']);
const canvas13State = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c13'], state);
const expandedNodeIds = getExpandedNodeIds(canvas13State, { companionWindowId: 'cw123', windowId: 'w1' });
expect(expandedNodeIds.length).toBe(0);
});
......@@ -168,30 +169,30 @@ describe('getNodeIdToScrollTo', () => {
});
it('returns branch node with visible canvas if it is the deepest in the tree to contain a canvas', () => {
const canvas10State = setIn(expandedNodesState, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c10']);
const canvas10State = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c10'], expandedNodesState);
expect(getNodeIdToScrollTo(canvas10State, { companionWindowId: 'cw123', windowId: 'w1' })).toBe('0-2-1');
});
it('returns the deepest non hidden branch node if leaf node or its parent node are collapsed', () => {
const closedParentState1 = setIn(state, ['companionWindows', 'cw123', 'tocNodes'], { '0-1-1': { expanded: false } });
const closedParentState1 = set(['companionWindows', 'cw123', 'tocNodes'], { '0-1-1': { expanded: false } }, state);
expect(getNodeIdToScrollTo(closedParentState1, { companionWindowId: 'cw123', windowId: 'w1' })).toBe('0-1-1');
const closedParentState2 = setIn(state, ['companionWindows', 'cw123', 'tocNodes'], {
const closedParentState2 = set(['companionWindows', 'cw123', 'tocNodes'], {
'0-1': { expanded: false },
'0-1-1': { expanded: false },
});
}, state);
expect(getNodeIdToScrollTo(closedParentState2, { companionWindowId: 'cw123', windowId: 'w1' })).toBe('0-1');
});
it('returns no node id if current canvas is not contained in any range', () => {
const singleViewState = setIn(expandedNodesState, ['windows', 'w1', 'view'], 'single');
const rangeFreeCanvasState = setIn(singleViewState, ['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c12']);
const singleViewState = set(['windows', 'w1', 'view'], 'single', expandedNodesState);
const rangeFreeCanvasState = set(['windows', 'w1', 'visibleCanvases'], ['http://foo.test/1/canvas/c12'], singleViewState);
expect(getNodeIdToScrollTo(rangeFreeCanvasState, { companionWindowId: 'cw123', windowId: 'w1' })).toBe(null);
});
});
describe('getDefaultSidebarVariant', () => {
it('returns thumbnail when no ranges exist', () => {
const noRangeState = setIn(state, ['manifests', 'mID', 'json'], noRangesJson);
const noRangeState = set(['manifests', 'mID', 'json'], noRangesJson, state);
expect(getDefaultSidebarVariant(noRangeState, { windowId: 'w1' })).toBe('item');
});
it('returns tableOfContents when ranges exist', () => {
......
......@@ -41,7 +41,6 @@
"dompurify": "^2.0.11",
"i18next": "^19.5.0",
"icomcom-react": "^1.0.1",
"immutable": "^4.0.0-rc.12",
"intersection-observer": "^0.10.0",
"isomorphic-unfetch": "^3.0.0",
"jss": "^10.3.0",
......
import { removeIn } from 'immutable';
import omit from 'lodash/omit';
import { Utils } from 'manifesto.js/dist-esmodule/Utils';
import ActionTypes from '../actions/action-types';
......@@ -64,7 +64,7 @@ export function accessTokensReducer(state = {}, action) {
},
};
case ActionTypes.RESET_AUTHENTICATION_STATE:
return removeIn(state, [action.tokenServiceId]);
return omit(state, action.tokenServiceId);
default:
return state;
}
......
import { removeIn } from 'immutable';
import omit from 'lodash/omit';
import ActionTypes from '../actions/action-types';
import { selectNextAuthService } from '../selectors/canvases';
......@@ -52,7 +52,7 @@ export const authReducer = (state = {}, action) => {
},
};
case ActionTypes.RESET_AUTHENTICATION_STATE:
return removeIn(state, [action.id]);
return omit(state, action.id);
default: return state;
}
};
import {
removeIn, setIn, updateIn, merge,
} from 'immutable';
import omit from 'lodash/omit';
import set from 'lodash/fp/set';
import update from 'lodash/fp/update';
import merge from 'lodash/fp/merge';
import ActionTypes from '../actions/action-types';
/** */
export function companionWindowsReducer(state = {}, action) {
switch (action.type) {
case ActionTypes.ADD_COMPANION_WINDOW:
return setIn(state, [action.id], action.payload);
return set([action.id], action.payload, state);
case ActionTypes.ADD_WINDOW:
return {
......@@ -30,14 +31,14 @@ export function companionWindowsReducer(state = {}, action) {
return object;
}, {});
case ActionTypes.UPDATE_COMPANION_WINDOW:
return updateIn(state, [action.id], orig => merge(orig, action.payload));
return update([action.id], orig => merge(orig, action.payload), state);
case ActionTypes.REMOVE_COMPANION_WINDOW:
return removeIn(state, [action.id]);
return omit(state, action.id);
case ActionTypes.IMPORT_MIRADOR_STATE:
return action.state.companionWindows || [];
case ActionTypes.TOGGLE_TOC_NODE:
return updateIn(state, [[action.id], 'tocNodes'], {}, orig => merge(orig, action.payload));
return update([action.id, 'tocNodes'], orig => merge(orig || {}, action.payload), state);
default:
return state;
}
......
import { updateIn, merge, removeIn } from 'immutable';
import update from 'lodash/fp/update';
import omit from 'lodash/omit';
import merge from 'lodash/fp/merge';
import ActionTypes from '../actions/action-types';
/**
......@@ -15,10 +17,10 @@ export const elasticLayoutReducer = (state = {}, action) => {
};
case ActionTypes.UPDATE_ELASTIC_WINDOW_LAYOUT:
return updateIn(state, [action.windowId], orig => merge(orig, action.payload));
return update([action.windowId], orig => merge(orig, action.payload), state);
case ActionTypes.REMOVE_WINDOW:
return removeIn(state, [action.windowId]);
return omit(state, action.windowId);
case ActionTypes.IMPORT_MIRADOR_STATE:
return action.state.elasticLayout || {};
default:
......
import {
removeIn,
} from 'immutable';
import omit from 'lodash/omit';
import deepmerge from 'deepmerge';
import ActionTypes from '../actions/action-types';
......@@ -21,7 +19,7 @@ export const layersReducer = (state = {}, action) => {
},
};
case ActionTypes.REMOVE_WINDOW:
return removeIn(state, [action.windowId]);
return omit(state, [action.windowId]);
default:
return state;
}
......
import {
removeIn,
} from 'immutable';
import omit from 'lodash/omit';
import flatten from 'lodash/flatten';
import ActionTypes from '../actions/action-types';
......@@ -130,14 +128,14 @@ export const searchesReducer = (state = {}, action) => {
case ActionTypes.IMPORT_MIRADOR_STATE:
return {};
case ActionTypes.REMOVE_WINDOW:
return removeIn(state, [action.windowId]);
return omit(state, action.windowId);
case ActionTypes.REMOVE_COMPANION_WINDOW:
if (!state[action.windowId]) return state;
return {
...state,
[action.windowId]: {
...removeIn(state[action.windowId], [action.id]),
...omit(state[action.windowId], action.id),
},
};
default: return state;
......
import { removeIn, setIn } from 'immutable';
import set from 'lodash/fp/set';
import omit from 'lodash/omit';
import ActionTypes from '../actions/action-types';
/**
......@@ -15,12 +16,12 @@ export const viewersReducer = (state = {}, action) => {
},
};
case ActionTypes.REMOVE_WINDOW:
return removeIn(state, [action.windowId]);
return omit(state, action.windowId);
case ActionTypes.SET_WINDOW_VIEW_TYPE:
return setIn(state, [action.windowId], null);
return set([action.windowId], null, state);
case ActionTypes.SET_CANVAS:
if (!action.preserveViewport) {
return setIn(state, [action.windowId], null);
return set([action.windowId], null, state);
}
return state;
case ActionTypes.IMPORT_MIRADOR_STATE:
......
import {
removeIn, updateIn, merge,
} from 'immutable';
import update from 'lodash/fp/update';
import omit from 'lodash/omit';
import merge from 'lodash/fp/merge';
import ActionTypes from '../actions/action-types';
/**
......@@ -29,10 +29,10 @@ export const windowsReducer = (state = {}, action) => {
};
case ActionTypes.UPDATE_WINDOW:
return updateIn(state, [action.id], orig => merge(orig, action.payload));
return update([action.id], orig => merge(orig, action.payload), state);
case ActionTypes.REMOVE_WINDOW:
return removeIn(state, [action.windowId]);
return omit(state, [action.windowId]);
case ActionTypes.TOGGLE_WINDOW_SIDE_BAR:
return {
...state,
......@@ -72,10 +72,10 @@ export const windowsReducer = (state = {}, action) => {
case ActionTypes.SET_CANVAS:
if (!state[action.windowId]) return state;
return updateIn(state, [action.windowId], orig => merge(orig, {
return update([action.windowId], orig => merge(orig, {
canvasId: action.canvasId,
visibleCanvases: action.visibleCanvases || [],
}));
}), state);
case ActionTypes.ADD_COMPANION_WINDOW:
return {
...state,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment