<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Trouble Using Reactive Utils On Initially Undefined Variable in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1703074#M88452</link>
    <description>&lt;P&gt;You’ll probably need to watch the object after it’s assigned, because watch() can’t keep tracking an undefined reference reliably. A cleaner approach is to watch the property that changes, or re-register the watcher once highlightHandles gets initialized. The initial: true option only fires once with the current value — it doesn’t wait for future definition changes.&lt;/P&gt;</description>
    <pubDate>Wed, 20 May 2026 11:11:27 GMT</pubDate>
    <dc:creator>RafelMayol</dc:creator>
    <dc:date>2026-05-20T11:11:27Z</dc:date>
    <item>
      <title>Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702952#M88445</link>
      <description>&lt;P&gt;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.&amp;nbsp; However, the variable is initially undefined and this seems to be causing an issue.&amp;nbsp; Even if I set the watch options to initial is true, the code will only execute the first time.&amp;nbsp; Is there a way for me to run it initially and then continue to monitor once the variable is defined? This is my code:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;reactiveUtils.watch(()=&amp;gt; globalThis.highlightHandles?._groups.size, () =&amp;gt;{

  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});&lt;/LI-CODE&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2026 20:36:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702952#M88445</guid>
      <dc:creator>JasonBartling1</dc:creator>
      <dc:date>2026-05-19T20:36:15Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702956#M88446</link>
      <description>&lt;P&gt;Try using a when before the watch.&amp;nbsp; Might want to use a {once: true} for the when.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;reactiveUtils.when(
  () =&amp;gt; globalThis.highlightHandles != null,
  () =&amp;gt; {

    reactiveUtils.watch(
      () =&amp;gt; globalThis.highlightHandles._groups.size,&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2026 20:45:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702956#M88446</guid>
      <dc:creator>MatthewDriscoll</dc:creator>
      <dc:date>2026-05-19T20:45:33Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702968#M88447</link>
      <description>&lt;P&gt;Unfortunately, that does not seem to work.&amp;nbsp; This is the updated code:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;reactiveUtils.when(()=&amp;gt; globalThis.highlightHandles != null, ()=&amp;gt;{
  reactiveUtils.watch(()=&amp;gt; globalThis.highlightHandles._groups.size, () =&amp;gt;{

    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;
    }

  });
});&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 19 May 2026 20:52:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702968#M88447</guid>
      <dc:creator>JasonBartling1</dc:creator>
      <dc:date>2026-05-19T20:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702971#M88448</link>
      <description>&lt;P&gt;This is one of those issues I usually slap a setTimeout() on.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;setTimeout(()=&amp;gt; {  
reactiveUtils.watch(()=&amp;gt; globalThis.highlightHandles._groups.size, () =&amp;gt;{

    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;
    }

  });
}, 100)&lt;/LI-CODE&gt;&lt;P&gt;It's not a best practice, but it usually works. Try dialing up or down the wait a few times and see if it works.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2026 20:57:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702971#M88448</guid>
      <dc:creator>JeffreyThompson2</dc:creator>
      <dc:date>2026-05-19T20:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702972#M88449</link>
      <description>&lt;P&gt;Try creating the variable like this instead.&amp;nbsp; Also _groups would make it private, so the API might not see it as observable.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;reactiveUtils.when(
  () =&amp;gt; globalThis.highlightHandles != null,
  () =&amp;gt; {

    reactiveUtils.watch(
      () =&amp;gt; globalThis.highlightHandles._groups.size,
      (numSelected) =&amp;gt; {...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2026 21:07:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702972#M88449</guid>
      <dc:creator>MatthewDriscoll</dc:creator>
      <dc:date>2026-05-19T21:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702975#M88450</link>
      <description>&lt;P&gt;The reactiveUtils only work against the SDK classes, not native objects and arrays, so we can't watch for changes on `globalThis`. The root object in the watchExpression needs to be an SDK class.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2026 21:13:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702975#M88450</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2026-05-19T21:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702978#M88451</link>
      <description>&lt;P&gt;Try this based off of&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/677423"&gt;@JeffreyThompson2&lt;/a&gt;&amp;nbsp;suggestion and what we have learned from&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7384"&gt;@ReneRubalcava&lt;/a&gt;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; setInterval(() =&amp;gt; {

  const numSelected = globalThis.highlightHandles?._groups?.size || 0;

  selectedCount.innerText = numSelected;

  console.log("Num selected is " + numSelected);

  if (numSelected) {
    selectedCount.style.color = 'black';
    moreActionsButton.disabled = false;
  } else {
    selectedCount.style.color = '#c9c9c9';
    moreActionsButton.disabled = true;
  }

}, 250);&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 19 May 2026 21:25:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1702978#M88451</guid>
      <dc:creator>MatthewDriscoll</dc:creator>
      <dc:date>2026-05-19T21:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1703074#M88452</link>
      <description>&lt;P&gt;You’ll probably need to watch the object after it’s assigned, because watch() can’t keep tracking an undefined reference reliably. A cleaner approach is to watch the property that changes, or re-register the watcher once highlightHandles gets initialized. The initial: true option only fires once with the current value — it doesn’t wait for future definition changes.&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2026 11:11:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1703074#M88452</guid>
      <dc:creator>RafelMayol</dc:creator>
      <dc:date>2026-05-20T11:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1703075#M88453</link>
      <description>&lt;P&gt;&lt;A href="https://fctv33hd.app/home/" target="_self"&gt;@FCTV33&lt;/A&gt;&amp;nbsp;You’ll probably need to watch the object after it’s assigned, because watch() can’t keep tracking an undefined reference reliably. A cleaner approach is to watch the property that changes, or re-register the watcher once highlightHandles gets initialized. The initial: true option only fires once with the current value — it doesn’t wait for future definition changes.&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2026 11:13:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1703075#M88453</guid>
      <dc:creator>RafelMayol</dc:creator>
      <dc:date>2026-05-20T11:13:21Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble Using Reactive Utils On Initially Undefined Variable</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1703172#M88454</link>
      <description>&lt;P&gt;Thanks Rene.&amp;nbsp; I did not realize it could only be used to track changes to the SDK objects.&amp;nbsp; Since I am also using a feature table to highlight, I ended up just watching the featureTable.highlightIds.length property.&amp;nbsp; This code worked for me:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;reactiveUtils.watch(()=&amp;gt; featureTable.highlightIds.length, (numSelected) =&amp;gt;{

  selectedCount.innerText = numSelected;

  if (numSelected &amp;gt; 0){

    selectedCount.style.color = 'black';
    moreActionsButton.disabled = false;
  }
  else {

    selectedCount.style.color = '#c9c9c9';
    moreActionsButton.disabled = true;
    
  }

});&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 20 May 2026 16:57:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/trouble-using-reactive-utils-on-initially/m-p/1703172#M88454</guid>
      <dc:creator>JasonBartling1</dc:creator>
      <dc:date>2026-05-20T16:57:55Z</dc:date>
    </item>
  </channel>
</rss>

