@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reearth/core",
3
- "version": "0.0.7-alpha.61",
3
+ "version": "0.0.7-alpha.62",
4
4
  "author": "Re:Earth contributors <community@reearth.io>",
5
5
  "license": "Apache-2.0",
6
6
  "description": "A library that abstracts a map engine as one common API.",
@@ -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 = getComputedLayer(id);
221
+ const layer = getComputedLayerRef.current(id);
216
222
  if (!layer) return undefined;
217
223
  return (layer as any)[key];
218
224
  },
219
225
  );
220
- }, [getComputedLayer]);
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 = getComputedLayer(layer.id);
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
- }, [getComputedLayer, layerMap, lazyComputedLayerPrototype]);
255
+ }, [layerMap, lazyComputedLayerPrototype]);
250
256
 
251
257
  const findById = useCallback(
252
258
  (layerId: string): LazyLayer | undefined => {