I have a global variable for highlight handles that I'm trying to watch to update a label with the number of currently selected features. However, the variable is initially undefined and this seems to be causing an issue. Even if I set the watch options to initial is true, the code will only execute the first time. Is there a way for me to run it initially and then continue to monitor once the variable is defined? This is my code:
reactiveUtils.watch(()=> globalThis.highlightHandles?._groups.size, () =>{
const numSelected = globalThis.highlightHandles?._groups.size;
selectedCount.innerText = numSelected;
console.log("Num selected is "+numSelected);
if (numSelected){
selectedCount.style.color = 'black';
moreActionsButton.disabled = false;
}
else {
selectedCount.innerText = "0";
selectedCount.style.color = '#c9c9c9';
moreActionsButton.disabled = true;
}
},{initial: true});Any help would be greatly appreciated!