@reearth/core 0.0.7-alpha.61 → 0.0.7-alpha.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core.js +5112 -5108
- package/dist/core.umd.cjs +42 -42
- package/package.json +1 -1
- package/src/Map/Layers/hooks.ts +10 -4
package/package.json
CHANGED
package/src/Map/Layers/hooks.ts
CHANGED
|
@@ -204,6 +204,12 @@ export default function useHooks({
|
|
|
204
204
|
),
|
|
205
205
|
);
|
|
206
206
|
|
|
207
|
+
// Store getComputedLayer in a ref to avoid recreating prototypes on every change
|
|
208
|
+
const getComputedLayerRef = useRef(getComputedLayer);
|
|
209
|
+
useEffect(() => {
|
|
210
|
+
getComputedLayerRef.current = getComputedLayer;
|
|
211
|
+
}, [getComputedLayer]);
|
|
212
|
+
|
|
207
213
|
const lazyComputedLayerPrototype = useMemo<object>(() => {
|
|
208
214
|
return objectFromGetter(
|
|
209
215
|
// id and layer should not be accessible
|
|
@@ -212,12 +218,12 @@ export default function useHooks({
|
|
|
212
218
|
const id: string | undefined = (this as any).id;
|
|
213
219
|
if (!id || typeof id !== "string") throw new Error("layer ID is not specified");
|
|
214
220
|
|
|
215
|
-
const layer =
|
|
221
|
+
const layer = getComputedLayerRef.current(id);
|
|
216
222
|
if (!layer) return undefined;
|
|
217
223
|
return (layer as any)[key];
|
|
218
224
|
},
|
|
219
225
|
);
|
|
220
|
-
}, [
|
|
226
|
+
}, []);
|
|
221
227
|
|
|
222
228
|
const lazyLayerPrototype = useMemo<object>(() => {
|
|
223
229
|
return objectFromGetter(layerKeys, function (key) {
|
|
@@ -237,7 +243,7 @@ export default function useHooks({
|
|
|
237
243
|
else if (key === "isVisible") return layer.visible;
|
|
238
244
|
// computed
|
|
239
245
|
else if (key === "computed") {
|
|
240
|
-
const computedLayer =
|
|
246
|
+
const computedLayer = getComputedLayerRef.current(layer.id);
|
|
241
247
|
if (!computedLayer) return undefined;
|
|
242
248
|
const computed = Object.create(lazyComputedLayerPrototype);
|
|
243
249
|
computed.id = id;
|
|
@@ -246,7 +252,7 @@ export default function useHooks({
|
|
|
246
252
|
|
|
247
253
|
return (layer as any)[key];
|
|
248
254
|
});
|
|
249
|
-
}, [
|
|
255
|
+
}, [layerMap, lazyComputedLayerPrototype]);
|
|
250
256
|
|
|
251
257
|
const findById = useCallback(
|
|
252
258
|
(layerId: string): LazyLayer | undefined => {
|