<?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: reactiveUtils in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196313#M78080</link>
    <description>&lt;P&gt;Thank you Undral! Take care.&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jul 2022 13:32:56 GMT</pubDate>
    <dc:creator>jasonwriter</dc:creator>
    <dc:date>2022-07-27T13:32:56Z</dc:date>
    <item>
      <title>reactiveUtils</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196114#M78071</link>
      <description>&lt;P&gt;Does anyone have an example of how to detect when a layer changes visibility? I'm trying to use the reactiveUtils but no luck.&amp;nbsp;&lt;/P&gt;&lt;P&gt;below is what I think should work and is in one of the reactiveUtils Samples but doesn't seem to work even in the sample. (it never triggers the callback function when i turn on and off layers).&lt;/P&gt;&lt;P&gt;// Use reactiveUtils to check when a Collection has changed&lt;BR /&gt;reactiveUtils.watch(&lt;BR /&gt;() =&amp;gt; [view.map.allLayers.forEach((layer) =&amp;gt; layer.visible)],&lt;BR /&gt;() =&amp;gt; {&lt;/P&gt;&lt;P&gt;console.log("layer visibiblity changed")&lt;BR /&gt;let layerNames = "";&lt;BR /&gt;renderVisibleLayers(layerNames);&lt;BR /&gt;}&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;Or perhaps there is a better way to set up an event listener on all my layers for visibility?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;Jason.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 20:29:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196114#M78071</guid>
      <dc:creator>jasonwriter</dc:creator>
      <dc:date>2022-07-26T20:29:28Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196125#M78072</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/109231"&gt;@jasonwriter&lt;/a&gt;have you checked out this sample&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/watch-for-changes-reactiveutils/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/watch-for-changes-reactiveutils/&lt;/A&gt; ?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 21:04:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196125#M78072</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2022-07-26T21:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196135#M78073</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I did confirm that watching layer visibility is not working in the sample you mentioned. We will get it fixed in the sample ASAP. Thank you for bringing this to our attention.&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can watch the operational layer visibilities the following way:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.when(()=&amp;gt;{
  view.map.layers.forEach((layer) =&amp;gt; {
    reactiveUtils.watch(() =&amp;gt; layer.visible, (visible) =&amp;gt; {
      console.log(layer.title, "visible:", layer.visible)
    });
  });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or for single layer you can just do the following:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;reactiveUtils.watch(() =&amp;gt; layer.visible, (visible) =&amp;gt; {
  console.log(layer.title, "visible:", layer.visible)
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 21:39:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196135#M78073</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2022-07-26T21:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196138#M78074</link>
      <description>&lt;P&gt;Hi Andy,&lt;/P&gt;&lt;P&gt;Thanks, that's the one I was trying to follow but the layer visibility code isn't working in the sample.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jul 2022 21:44:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196138#M78074</guid>
      <dc:creator>jasonwriter</dc:creator>
      <dc:date>2022-07-26T21:44:20Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196313#M78080</link>
      <description>&lt;P&gt;Thank you Undral! Take care.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 13:32:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196313#M78080</guid>
      <dc:creator>jasonwriter</dc:creator>
      <dc:date>2022-07-27T13:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196416#M78083</link>
      <description>&lt;P&gt;Hey there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works too:&amp;nbsp;&lt;SPAN&gt;[view.map.allLayers.map((layer) =&amp;gt; layer.visible)]&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 16:09:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1196416#M78083</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2022-07-27T16:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1197659#M78114</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/109231"&gt;@jasonwriter&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;Thanks for catching this. Using &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Collection.html#forEach" target="_self"&gt;Collection.forEach()&lt;/A&gt; worked in version 4.23 and in 4.24 we made a change to avoid calling the callback when the return value is the same. With forEach() the return value is always the same so using &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Collection.html#map" target="_self"&gt;Collection.map()&lt;/A&gt; fixes this issue.&lt;/P&gt;&lt;P&gt;The sample will be updated to use map() mid week next week. Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jul 2022 23:32:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils/m-p/1197659#M78114</guid>
      <dc:creator>LaurenBoyd</dc:creator>
      <dc:date>2022-07-29T23:32:34Z</dc:date>
    </item>
  </channel>
</rss>

