Skip to content

Commit

Permalink
Lodash.memoize typings added (#1827)
Browse files Browse the repository at this point in the history
Signed-off-by: Daria Terekhova <daria.terekhova@actionengine.com>
  • Loading branch information
dariaterekhova-actionengine committed Jun 3, 2022
1 parent 69f8534 commit 1034c33
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -114,6 +114,7 @@
"@types/lodash.flattendeep": "^4.4.7",
"@types/lodash.get": "^4.4.6",
"@types/lodash.isequal": "^4.5.5",
"@types/lodash.memoize": "^4.1.7",
"@types/lodash.pick": "^4.4.6",
"@types/lodash.throttle": "^4.1.7",
"@types/lodash.uniq": "^4.5.7",
Expand Down
14 changes: 10 additions & 4 deletions src/reducers/map-style-updaters.ts
Expand Up @@ -184,6 +184,13 @@ const mapStyleUpdaters = null;
*/
export const INITIAL_MAP_STYLE: MapStyle = getDefaultState();

interface GetMapStylesParam {
styleType: string;
visibleLayerGroups: {[id: string]: LayerGroup | boolean};
topLayerGroups: {[id: string]: LayerGroup | boolean};
mapStyles: {[id: string]: any}
}

/**
* Create two map styles from preset map style, one for top map one for bottom
*
Expand All @@ -193,7 +200,7 @@ export const INITIAL_MAP_STYLE: MapStyle = getDefaultState();
* @param {Object} mapStyles - a dictionary of all map styles
* @returns {Object} bottomMapStyle | topMapStyle | isRaster
*/
export function getMapStyles({styleType, visibleLayerGroups, topLayerGroups, mapStyles}) {
export function getMapStyles({styleType, visibleLayerGroups, topLayerGroups, mapStyles}: GetMapStylesParam) {
const mapStyle = mapStyles[styleType];

// style might not be loaded yet
Expand All @@ -211,7 +218,7 @@ export function getMapStyles({styleType, visibleLayerGroups, topLayerGroups, map
visibleLayerGroups
});

const hasTopLayer = editable && Object.values(topLayerGroups).some(v => v);
const hasTopLayer = editable > 0 && Object.values(topLayerGroups).some(v => v);

// mute top layer if not visible in bottom layer
const topLayers =
Expand All @@ -221,12 +228,11 @@ export function getMapStyles({styleType, visibleLayerGroups, topLayerGroups, map
...accu,
[key]: topLayerGroups[key] && visibleLayerGroups[key]
}),
{}
{} as {[id: string]: LayerGroup | boolean}
);

const topMapStyle = hasTopLayer
? editTopMapStyle({
id: styleType,
mapStyle,
visibleLayerGroups: topLayers
})
Expand Down
4 changes: 2 additions & 2 deletions src/utils/map-style-utils/mapbox-gl-style-editor.ts
Expand Up @@ -36,7 +36,7 @@ export function getDefaultLayerGroupVisibility({layerGroups = []}: {layerGroups:
);
}

const resolver = ({id, mapStyle, visibleLayerGroups = {}}) =>
const resolver = ({id, mapStyle, visibleLayerGroups = {}}: {id?: string; mapStyle: BaseMapStyle; visibleLayerGroups: {[id: string]: LayerGroup | boolean} | false}) =>
`${id}:${Object.keys(visibleLayerGroups)
.filter(d => visibleLayerGroups[d])
.sort()
Expand All @@ -50,7 +50,7 @@ const resolver = ({id, mapStyle, visibleLayerGroups = {}}) =>
* @returns top map style
*/
export const editTopMapStyle = memoize(
({mapStyle, visibleLayerGroups}: {mapStyle: BaseMapStyle; visibleLayerGroups: LayerGroup[]}) => {
({mapStyle, visibleLayerGroups}: {mapStyle: BaseMapStyle; visibleLayerGroups: {[id: string]: LayerGroup | boolean} | false}) => {
const visibleFilters = (mapStyle.layerGroups || [])
.filter(lg => visibleLayerGroups[lg.slug])
.map(lg => lg.filter);
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Expand Up @@ -3317,6 +3317,13 @@
dependencies:
"@types/lodash" "*"

"@types/lodash.memoize@^4.1.7":
version "4.1.7"
resolved "https://registry.yarnpkg.com/@types/lodash.memoize/-/lodash.memoize-4.1.7.tgz#aff94ab32813c557cbc1104e127030e3d60a3b27"
integrity sha512-lGN7WeO4vO6sICVpf041Q7BX/9k1Y24Zo3FY0aUezr1QlKznpjzsDk3T3wvH8ofYzoK0QupN9TWcFAFZlyPwQQ==
dependencies:
"@types/lodash" "*"

"@types/lodash.pick@^4.4.6":
version "4.4.6"
resolved "https://registry.yarnpkg.com/@types/lodash.pick/-/lodash.pick-4.4.6.tgz#ae4e8f109e982786313bb6aac4b1a73aefa6e9be"
Expand Down

0 comments on commit 1034c33

Please sign in to comment.