Skip to content

Commit

Permalink
[Bug] Fix composer types, schema types (#2208)
Browse files Browse the repository at this point in the history
Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>
Co-authored-by: Shan He <heshan0131@gmail.com>
  • Loading branch information
igorDykhta and heshan0131 committed Apr 28, 2023
1 parent 28fbcdb commit e5686fd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/src/side-panel/layer-panel/layer-list.tsx
Expand Up @@ -132,7 +132,7 @@ function LayerListFactory(LayerPanel: ReturnType<typeof LayerPanelFactory>) {

const layersToShow = useMemo(() => {
return layerOrder.reduce((acc, layerId) => {
const layer = findById<Layer>(layerId)(layers);
const layer = findById(layerId)(layers);
if (!layer) {
return acc;
}
Expand Down
2 changes: 1 addition & 1 deletion src/layers/src/mapbox-utils.ts
Expand Up @@ -42,7 +42,7 @@ export function generateMapboxLayers(
.slice()
.reverse()
.filter(layerId => {
const layer = findById<Layer>(layerId)(layers);
const layer = findById(layerId)(layers);
return layer?.overlayType === OVERLAY_TYPE_CONST.mapboxgl && layersToRender[layerId];
})
.reduce((acc, layerId) => {
Expand Down
5 changes: 2 additions & 3 deletions src/reducers/src/composer-helpers.ts
Expand Up @@ -38,9 +38,8 @@ export function apply_<State, P>(
return state => updater(state, payload);
}

export function with_<State>(
fn: (state: State) => (nextState: State) => State
): (state: State) => State {
type Arg<State> = (state: State) => (nextState: State) => State;
export function with_<State>(fn: Arg<State>): (state: State) => State {
return state => fn(state)(state);
}

Expand Down
2 changes: 1 addition & 1 deletion src/schemas/src/vis-state-schema.ts
Expand Up @@ -573,7 +573,7 @@ export class LayerSchemaV0 extends Schema {
return {
[this.key as 'layers']: visState.layerOrder.reduce((saved, layerId) => {
// save layers according to their rendering order
const layer = findById<Layer>(layerId)(layers);
const layer = findById(layerId)(layers);
if (layer?.isValidToSave()) {
saved.push(this.savePropertiesOrApplySchema(layer).layers);
}
Expand Down
8 changes: 4 additions & 4 deletions src/utils/src/utils.ts
Expand Up @@ -212,17 +212,17 @@ export function isFunction(func) {
return typeof func === 'function';
}

export function findById<X extends {id: string}>(id: string): (arr: X[]) => X | undefined {
export function findById(id: string): <X extends {id: string}>(arr: X[]) => X | undefined {
return arr => arr.find(a => a.id === id);
}

/**
* Returns array difference from
*/
export function arrayDifference<X extends {id: string}>(origin: X[]): (compare: X[]) => X[] {
export function arrayDifference<X extends {id: string}>(source: X[]): (compare: X[]) => X[] {
return compare =>
origin.reduce((acc, element) => {
const foundElement = findById<X>(element.id)(compare);
source.reduce((acc, element) => {
const foundElement = findById(element.id)(compare);
return foundElement ? [...acc, foundElement] : acc;
}, [] as X[]);
}

0 comments on commit e5686fd

Please sign in to comment.