<?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.watch() on a custom class? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1604305#M86862</link>
    <description>&lt;P&gt;Did this end up working out, or did you find something else more suitable?&lt;/P&gt;</description>
    <pubDate>Wed, 09 Apr 2025 18:09:52 GMT</pubDate>
    <dc:creator>JoelBennett</dc:creator>
    <dc:date>2025-04-09T18:09:52Z</dc:date>
    <item>
      <title>reactiveUtils.watch() on a custom class?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1599205#M86754</link>
      <description>&lt;P&gt;I'm starting to lean more on `reactiveUtils.watch()` for reactivity that isn't easily handled by my JavaScript framework. Generally, things are going well, but I'm running into an issue with unit/integration tests:&lt;/P&gt;&lt;P&gt;A common issue is that I will want to stub or mock a JS SDK class. For example, I frequently create a fake WebMap with fake layers:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;class FakeLayer {
  constructor({ id, listMode, visible, type }) {
    this.id = id;
    this.listMode = listMode;
    this.visible = visible;
    this.type = type;
  }

  when = async () =&amp;gt; true;
}

const fakeWebMap = {
    allLayers: [
      new FakeLayer({
        id: 'layer-1',
        listMode: 'hide',
        visible: true,
      }),
      new FakeLayer({
        id: 'layer-2',
        listMode: 'hide',
        visible: false,
      }),
      new FakeLayer({
        id: 'layer-3',
        listMode: 'show',
        visible: true,
      }),
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem is this:&amp;nbsp;&lt;STRONG&gt;reactiveUtils.watch()&lt;/STRONG&gt;&amp;nbsp;&lt;STRONG&gt;does not seem to work on POJOs or custom classes&amp;nbsp;&lt;/STRONG&gt;like FakeLayer above.&lt;/P&gt;&lt;P&gt;In the example above, I might be testing code that&amp;nbsp;&lt;STRONG&gt;watch&lt;/STRONG&gt;es the `visible` property on each FakeLayer and mutates `listMode` if `visible` changes.&amp;nbsp;&lt;STRONG&gt;How can I implement a mock/stub testing class that works with reactiveUtils.watch()?&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Mar 2025 20:37:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1599205#M86754</guid>
      <dc:creator>fdeters</dc:creator>
      <dc:date>2025-03-25T20:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils.watch() on a custom class?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1599275#M86757</link>
      <description>&lt;P&gt;Have you considered extending the Accessor class?&amp;nbsp; See also &lt;A href="https://developers.arcgis.com/javascript/latest/implementing-accessor/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/implementing-accessor/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 02:21:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1599275#M86757</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2025-03-26T02:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils.watch() on a custom class?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1599748#M86760</link>
      <description>&lt;P&gt;This looks like exactly the starting point I was looking for, thanks. I'll come back and accept as solution once I've seen if it works for what I need.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Mar 2025 21:38:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1599748#M86760</guid>
      <dc:creator>fdeters</dc:creator>
      <dc:date>2025-03-26T21:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils.watch() on a custom class?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1604305#M86862</link>
      <description>&lt;P&gt;Did this end up working out, or did you find something else more suitable?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 18:09:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1604305#M86862</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2025-04-09T18:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: reactiveUtils.watch() on a custom class?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1605399#M86911</link>
      <description>&lt;P&gt;Actually, yes! I just got it to work moments ago. I used this section of the article you linked:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/implementing-accessor/#define-a-simple-property" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/implementing-accessor/#define-a-simple-property&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here's what my solution looks like for setting up a single property that I can use reactiveUtils.watch() on:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const MyCustomClass = Accessor.createSubclass({
  constructor: function () {
    this.myProperty = null;
  },

  properties: {
    myProperty: {},
  },
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wanted to use native classes, but neither of the following were working for me (I'm not using TypeScript):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// native class using the @property decorator
class MyCustomClass extends Accessor {
  @property
  state = null;
}

// native class, no decorators
class MyCustomClass extends Accessor {
  constructor() {
    super(...arguments);
    this.myProperty= null;
  }

  properties = {
    myProperty: {},
  };
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Apr 2025 22:50:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/reactiveutils-watch-on-a-custom-class/m-p/1605399#M86911</guid>
      <dc:creator>fdeters</dc:creator>
      <dc:date>2025-04-11T22:50:54Z</dc:date>
    </item>
  </channel>
</rss>

