I’m passing a map to a component and then emit back new values and update the map. This triggers the watch on the map, but the old and new values passed are the same.
Is it possible in this case to have a watch that receives old values?
(function() {
const ui = {
setup() {
const map = reactive(new Map([
['width', 800],
['height', 400]
]));
function onCompUpdate(evt) {
console.log(map.get('width'), map.get('height'), evt[0], evt[1]);
map.set('width', Number(evt[0]));
map.set('height', Number(evt[1]));
}
watch(map, (n,o)=>{
console.log(n.get('width'), n.get('height'),
o.get('width'), o.get('height'));
});
return { map, onCompUpdate };
},
};
const vueApp = createApp(ui);
vueApp.component('base-input', {
props: ['some' ], emits: ['comp-update'],
setup(props, { emit }) {
let chars = ref(Array.from(props.some.values()).join(','));
function checkInput(val) {
emit('comp-update', val.split(','));
chars.value = val;
}
return { chars, checkInput };
},
template: `<input type="text" spellcheck="false" :value="chars"
input="checkInput($event.target.value)"/>`
});
vueApp.mount('#vue');
})();
HTML:
<div id="vue">
<base-input :some="map" @comp-update="onCompUpdate($event)"></base-input>
</div>