i am using vue3 with options api
for the storeTest.vue
posted below, every time i set a value to it, the respective wachter
gets executed, but it also gets excuted even if the i set the same object twice!!
according to my understanding, the wachter
in code section watch
posted below should be executed if only the store
is set to different value of the object.
please let me know why the code in section watch
posted below gets executed even if i set the same value to the StoreTest
twice?
code:
StoreTest.setters.set({
geojson: this.#featureRecentlyRequestedProcessing.value.get(DigitizePolygonConstants.CONST_DIGITIZED_FEATURE_PROPERTY_GEOJSON.description),
order: this.#featureRecentlyRequestedProcessing.value.get(DigitizePolygonConstants.CONST_DIGITIZED_FEATURE_PROPERTY_GEOM_ORDER.description),
});
storeTest.vue:
<script>
import { reactive } from 'vue';
export default {
}
export const StoreTest = ({
state: reactive({
array: [],
}),
getters: {
get() {
return StoreTest.state.array;
},
},
setters: {
set(obj) {
StoreTest.state.array.push(obj);
},
},
actions: {
initialize() {
StoreTest.state.array = [];
},
}
});
</script>
watch:
created() {
console.log(verboseTag, 'created()');
this.$watch(this.refStoreTest.getters.get, (newVal, oldVal) => {
msg = JSON.stringify({msg: verboseTag + '@watch refStoreTest.getters.get()', newVal: newVal, oldVal: oldVal});
console.log(msg);
newVal = newVal.sort((a,b) => a.order-b.order);
this.refStroeRecentlyHoveredGeometriesProps.setters.set(newVal);
}, { deep: true });
}