Skip to content

Commit

Permalink
fix: remove copyLazyLayer on reearth/core (#519)
Browse files Browse the repository at this point in the history
fix: remove copyLazyLayer
  • Loading branch information
keiya01 committed Mar 7, 2023
1 parent 4a5ba4b commit e172186
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 48 deletions.
22 changes: 9 additions & 13 deletions src/core/Crust/Plugins/api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Tag } from "@reearth/core/mantle/compat";
import {
copyLazyLayer,
Events,
Layer,
LayerSelectionReason,
LayersRef,
NaiveLayer,
LazyLayer,
copyLazyLayers,
} from "@reearth/core/Map";
import { merge } from "@reearth/util/object";

Expand Down Expand Up @@ -484,7 +482,7 @@ export function commonReearth({
return !!layers()?.isLayer;
},
get layers() {
return copyLazyLayers(layers()?.layers()) ?? [];
return layers()?.layers() ?? [];
},
get tags() {
return tags();
Expand All @@ -505,29 +503,27 @@ export function commonReearth({
return selectedFeature();
},
get findById() {
return (id: string) => copyLazyLayer(layers()?.findById(id));
return (id: string) => layers()?.findById(id);
},
get findByIds() {
return (...args: string[]) =>
copyLazyLayers(
layers()
?.findByIds(...args)
?.filter((l): l is LazyLayer => !!l),
);
layers()
?.findByIds(...args)
?.filter((l): l is LazyLayer => !!l);
},
get findByTags() {
return (...args: string[]) => copyLazyLayers(layers()?.findByTags(...args));
return (...args: string[]) => layers()?.findByTags(...args);
},
get findByTagLabels() {
return (...args: string[]) => copyLazyLayers(layers()?.findByTagLabels(...args));
return (...args: string[]) => layers()?.findByTagLabels(...args);
},
get find() {
return (cb: (layer: LazyLayer, index: number, parents: LazyLayer[]) => boolean) =>
copyLazyLayer(layers()?.find(cb));
layers()?.find(cb);
},
get findAll() {
return (cb: (layer: LazyLayer, index: number, parents: LazyLayer[]) => boolean) =>
copyLazyLayers(layers()?.findAll(cb));
layers()?.findAll(cb);
},
get override() {
return layers()?.override;
Expand Down
1 change: 0 additions & 1 deletion src/core/Map/Layers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export type {
ClusterProperty,
Cluster,
} from "../ClusteredLayers";
export { copyLazyLayers, copyLazyLayer } from "./utils";

export type Props = Omit<ClusteredLayerProps, "atomMap" | "isHidden"> & {
hiddenLayers?: string[];
Expand Down
33 changes: 0 additions & 33 deletions src/core/Map/Layers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { isArray, isObject } from "lodash-es";

import { LazyLayer } from "./hooks";
import { layerKeys, computedLayerKeys } from "./keys";

export const deepAssign = <O extends Record<string, any>>(obj: O, src: O) => {
return Object.fromEntries(
Object.entries({ ...src, ...obj })
Expand Down Expand Up @@ -38,33 +35,3 @@ export const deepAssign = <O extends Record<string, any>>(obj: O, src: O) => {
.filter((v): v is [string, any] => !!v),
) as O;
};

export const copyLazyLayers = (layers: LazyLayer[] | undefined) => {
return layers?.map(l => {
return copyLazyLayer(l);
});
};

export const copyLazyLayer = (l: LazyLayer | undefined) => {
return layerKeys.reduce((res, key) => {
if (key === "computed") {
res = {
...res,
get [key]() {
return computedLayerKeys.reduce((computedRes, computedKey) => {
computedRes[computedKey] = l?.[key as keyof LazyLayer]?.[computedKey];
return computedRes;
}, {} as Record<string, any>);
},
};
return res;
}
res[key] = {
...res,
get [key]() {
return l?.[key as keyof LazyLayer];
},
};
return res;
}, {} as Record<string, any>) as LazyLayer;
};
1 change: 0 additions & 1 deletion src/core/Map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { Engine, EngineProps } from "./types";

export * from "./types";
export { useGet, type WrappedRef, type Undefinable, useOverriddenProperty } from "./utils";
export { copyLazyLayers, copyLazyLayer } from "./Layers";

export type {
NaiveLayer,
Expand Down

0 comments on commit e172186

Please sign in to comment.