From d5d55f7437c2bf0f28b49ac60d2b8b4abe899999 Mon Sep 17 00:00:00 2001 From: razorness <684302+razorness@users.noreply.github.com> Date: Mon, 12 Feb 2024 19:21:02 +0100 Subject: [PATCH] minor performance tweak --- package.json | 2 +- src/lib/components/sources/canvas.source.ts | 6 +----- src/lib/components/sources/geojson.source.ts | 8 ++++---- src/lib/components/sources/image.source.ts | 6 +----- src/lib/components/sources/vector.source.ts | 12 ++---------- src/lib/components/sources/video.source.ts | 6 +----- 6 files changed, 10 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 556c851..547fdbc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-maplibre-gl", - "version": "3.1.2", + "version": "3.1.3", "description": "Vue 3 plugin for maplibre-gl", "keywords": [ "vue", diff --git a/src/lib/components/sources/canvas.source.ts b/src/lib/components/sources/canvas.source.ts index d97e19e..937a621 100644 --- a/src/lib/components/sources/canvas.source.ts +++ b/src/lib/components/sources/canvas.source.ts @@ -35,11 +35,7 @@ export default /*#__PURE__*/ defineComponent({ useSource(source, props, 'canvas', sourceOpts, registry); watch(isRef(props.coordinates) ? props.coordinates : () => props.coordinates, v => { - if (isRef(v) && v.value) { - source.value?.setCoordinates(v.value as Coordinates); - } else if (v) { - source.value?.setCoordinates(v as Coordinates); - } + source.value?.setCoordinates(v as Coordinates); }, { immediate: true }); return () => [ diff --git a/src/lib/components/sources/geojson.source.ts b/src/lib/components/sources/geojson.source.ts index 4d190ba..05c99a7 100644 --- a/src/lib/components/sources/geojson.source.ts +++ b/src/lib/components/sources/geojson.source.ts @@ -23,6 +23,8 @@ const sourceOpts = AllSourceOptions({ filter : undefined, }); +type DataType = GeoJSON.Feature | GeoJSON.FeatureCollection | string; + export default /*#__PURE__*/ defineComponent({ name : 'MglGeoJsonSource', @@ -31,7 +33,7 @@ export default /*#__PURE__*/ defineComponent({ type : String as PropType, required: true }, - data : [ Object, String ] as PropType | GeoJSON.FeatureCollection | string>, + data : [ Object, String ] as PropType, maxzoom : Number as PropType, attribution : String as PropType, buffer : Number as PropType, @@ -59,9 +61,7 @@ export default /*#__PURE__*/ defineComponent({ useSource(source, props, 'geojson', sourceOpts, registry); watch(isRef(props.data) ? props.data : () => props.data, v => { - source.value?.setData(isRef(v) ? (v.value || { type: 'FeatureCollection', features: [] }) : (v as any || { - type: 'FeatureCollection', features: [] - })); + source.value?.setData(v as DataType || { type: 'FeatureCollection', features: [] }); }, { immediate: true }); return () => [ diff --git a/src/lib/components/sources/image.source.ts b/src/lib/components/sources/image.source.ts index bb8e2f1..325a55e 100644 --- a/src/lib/components/sources/image.source.ts +++ b/src/lib/components/sources/image.source.ts @@ -33,11 +33,7 @@ export default /*#__PURE__*/ defineComponent({ useSource(source, props, 'image', sourceOpts, registry); watch(isRef(props.coordinates) ? props.coordinates : () => props.coordinates, v => { - if (isRef(v) && v.value) { - source.value?.setCoordinates(v.value as Coordinates); - } else if (v) { - source.value?.setCoordinates(v as Coordinates); - } + source.value?.setCoordinates(v as Coordinates); }, { immediate: true }); return () => [ diff --git a/src/lib/components/sources/vector.source.ts b/src/lib/components/sources/vector.source.ts index c6461d3..9fe5350 100644 --- a/src/lib/components/sources/vector.source.ts +++ b/src/lib/components/sources/vector.source.ts @@ -47,18 +47,10 @@ export default /*#__PURE__*/ defineComponent({ useSource(source, props, 'vector', sourceOpts, registry); watch(isRef(props.tiles) ? props.tiles : () => props.tiles, v => { - if (isRef(v)) { - source.value?.setTiles(v.value as string[] || []) - } else { - source.value?.setTiles(v as string[] || []) - } + source.value?.setTiles(v as string[] || []) }, { immediate: true }); watch(isRef(props.url) ? props.url: () => props.url, v => { - if (isRef(v)) { - source.value?.setUrl(v.value as string || '') - } else { - source.value?.setUrl(v as string || '') - } + source.value?.setUrl(v as string || '') }, { immediate: true }); return () => [ diff --git a/src/lib/components/sources/video.source.ts b/src/lib/components/sources/video.source.ts index f91b6fd..04410a3 100644 --- a/src/lib/components/sources/video.source.ts +++ b/src/lib/components/sources/video.source.ts @@ -33,11 +33,7 @@ export default /*#__PURE__*/ defineComponent({ useSource(source, props, 'video', sourceOpts, registry); watch(isRef(props.coordinates) ? props.coordinates : () => props.coordinates, v => { - if (isRef(v) && v.value) { - source.value?.setCoordinates(v.value as Coordinates); - } else if (v) { - source.value?.setCoordinates(v as Coordinates); - } + source.value?.setCoordinates(v as Coordinates); }, { immediate: true }); return () => [