<?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: handling and rendering in a widget in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074422#M73706</link>
    <description>&lt;P&gt;Just a quick follow-up, I tested the above code and it worked. Here's some more psuedo-code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    //Add widget to component
    this.simpleWidget = new SimpleWidget2({
       container: document.createElement("div")
    });
    // Be sure to add widget to the view
    this.view.ui.add(this.simpleWidget, "bottom-right");      

    // After map initialized and widget has been added to the component
    let count = 0;
    const c = this.simpleWidget.container.addEventListener("click", () =&amp;gt; {
        this.simpleWidget.msg = "test" + this.count++;
    })&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Jun 2021 20:46:02 GMT</pubDate>
    <dc:creator>AndyGup</dc:creator>
    <dc:date>2021-06-30T20:46:02Z</dc:date>
    <item>
      <title>handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1072943#M73635</link>
      <description>&lt;P&gt;I have a simple logic working that I want to make a widget out of.&lt;/P&gt;&lt;P&gt;i have a problem implementing it inside the render() function.&lt;/P&gt;&lt;P&gt;the current state is i created the widget, and the individual functions work but once inside the are called dozens of times.&lt;/P&gt;&lt;P&gt;what is the correct way to call them from the render?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;widget params:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;---&lt;STRONG&gt;featurelayer&lt;/STRONG&gt; - from drop down list chosen by the user. - the list created on widget start and updates when map changes(layers get added or removed).&lt;/P&gt;&lt;P&gt;---range -&lt;STRONG&gt;number&lt;/STRONG&gt; - for querying the layer - from user&lt;/P&gt;&lt;P&gt;---enabled - &lt;STRONG&gt;boolean&lt;/STRONG&gt; - is querying active? - changes on click&amp;nbsp;&lt;/P&gt;&lt;P&gt;all this logic already works a quick overview of the four &lt;STRONG&gt;functions and watch:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;---populateLayerList - &lt;/STRONG&gt;creates feature layer List select&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;---onMapChange() function - calls populate function&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;watch for webmap changes and recreate dropdown list&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;---toggleQueryButton -&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;true or false activates the view watch for user click on map and query the layer.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;---executeQuery()&lt;/STRONG&gt; - gets the params and adds graphic layer to the map&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Widget from "@arcgis/core/widgets/Widget";
import MapView from "@arcgis/core/views/MapView";
import WebMap from "@arcgis/core/WebMap";
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
import Graphic from "@arcgis/core/Graphic";
import { subclass, property } from "@arcgis/core/core/accessorSupport/decorators";
import { tsx } from "@arcgis/core/widgets/support/widget";

import FeatureLayer from "@arcgis/core/layers/FeatureLayer";

@subclass("esri.widgets.SimpleWidget")
class SimpleWidget extends Widget {

    constructor(map: WebMap, mapView: MapView) {
        super();
        this.map = map;
        this.view = mapView;

    }

    @property()
    enabled: boolean = false

    @property()
    map: WebMap  //| null = null

    @property()
    view: MapView //| null = null


    render() {
        let dropdown = this.populateLayerList()
        this.onMapChange()
        // widget container
        // layer list to get all layers of the view - updates when change happens
        // meter range for query
        // execute button toggles on/of view.on click event that creates the query 
        //
        return &amp;lt;div class="groundZeroWidget"&amp;gt;
            {dropdown}
            &amp;lt;input id="queryRange" type="number" /&amp;gt;
            &amp;lt;button onclick={this.toggleQueryButton()}&amp;gt;execute&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    }

    //creates the list of feature layers on open and on change
    private populateLayerList() {

        console.log("populateLayerList");

        let layerList: FeatureLayer[] = [] //list of all feature layers

        this.map.allLayers.forEach((x: FeatureLayer) =&amp;gt; {
            if (x.type == "feature") {
                console.log(x.title);
                layerList.push(x) //list of layer titles
            }
        });

        function MakeItem(x: FeatureLayer) {
            return &amp;lt;option key={x}&amp;gt;{x.title}&amp;lt;/option&amp;gt;;
        };


        return &amp;lt;select id="layerTitleList" &amp;gt;{layerList.map(MakeItem)}&amp;lt;/select&amp;gt;;


    }

    private onMapChange() {

        this.map.allLayers.on("change", function (event) {
            console.log("onMapChange");
            
            // change event fires after an item has been added, moved or removed from the collection.
            // event.moved - an array of moved layers
            // event.removed - an array of removed layers
            // event.added returns an array of added layers

            // this.populateLayerList() ----------not stable yet
        })

    }

    // toggles widget active, changes button color 
    private toggleQueryButton() {
        
        console.log('toggleQueryButton');

        let layerList: __esri.Collection&amp;lt;FeatureLayer&amp;gt; | FeatureLayer[] = [] //list of all feature layers
        this.map.allLayers.forEach((x: FeatureLayer) =&amp;gt; {
            if (x.type == "feature") {
                layerList.push(x)
            }
        });

        (this.enabled) ? (this.enabled = false) : (this.enabled = true) //toggles widget active
        console.log("enabled?:" + this.enabled);
        // change button color


        this.view.on("click", (event) =&amp;gt; {
            console.log("click event: ", event.mapPoint);
            let groundZeroXY = event.mapPoint;
            if (this.enabled) {
                this.executeQuery(groundZeroXY, layerList);
            }
        });
    }
    //when active creates layer from specifications and adds it to the map 
    private executeQuery(screenPoint: __esri.MapViewScreenPoint, layerList: any[] | __esri.Collection&amp;lt;FeatureLayer&amp;gt;) {

        console.log("executeQuery");
        
        //get selected layer
        let layerTitle = (document.getElementById('layerTitleList') as HTMLSelectElement).value
        console.log(layerTitle);

        let queryLayer: FeatureLayer = layerList.find(x =&amp;gt; x.title == layerTitle);

        //get selected range
        let range = (document.getElementById('queryRange') as HTMLInputElement).value;

        console.log("range: " + range);

        let Glayer = new GraphicsLayer();

        let map = this.map

        const point = this.view.toMap(screenPoint);

        // Query the for the items within x-KM from where the user clicked for layer x
        var query = queryLayer.createQuery();
        query.geometry = point;
        query.spatialRelationship = "intersects";
        query.distance = parseInt(range);
        query.units = "meters";
        query.returnGeometry = true;
        query.outFields = ["*"];
        queryLayer.queryFeatures(query).then(function (res: __esri.FeatureSet) {
            if (res.features.length === 0) {
                console.log("no items 1st layer");
            }

            console.log(res.features);
            console.log(res.features[0]);

            let graphic: Graphic[] = res.features;


            Glayer.addMany(graphic);
            map.add(Glayer);

            if (Glayer.graphics.length === 0) {
                console.log("no featuers");
            }
        });
    }

}
export = SimpleWidget;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 15:48:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1072943#M73635</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-06-26T15:48:31Z</dc:date>
    </item>
    <item>
      <title>handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1072942#M73636</link>
      <description>&lt;P&gt;I have a simple logic working that I want to make a widget out of.&lt;/P&gt;&lt;P&gt;i have a problem implementing it inside the render() function.&lt;/P&gt;&lt;P&gt;the current state is i created the widget, and the individual functions work but once inside the are called dozens of times.&lt;/P&gt;&lt;P&gt;what is the correct way to call them from the render?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;widget params:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;featurelayer&lt;/STRONG&gt; - from drop down list chosen by the user. - the list created on widget start and updates when map changes(layers get added or removed).&lt;/P&gt;&lt;P&gt;range -&lt;STRONG&gt;number&lt;/STRONG&gt; - for querying the layer - from user&lt;/P&gt;&lt;P&gt;enabled - &lt;STRONG&gt;boolean&lt;/STRONG&gt; - is querying active? - changes on click&amp;nbsp;&lt;/P&gt;&lt;P&gt;all this logic already works a quick overview of the four &lt;STRONG&gt;functions and watch:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;populateLayerList - &lt;/STRONG&gt;creates feature layer List select&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;onMapChange() function - calls populate function&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;watch for webmap changes and recreate dropdown list&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;toggleQueryButton -&amp;nbsp;&lt;/STRONG&gt;&amp;nbsp;true or false activates the view watch for user click on map and query the layer.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;executeQuery()&lt;/STRONG&gt; - gets the params and adds graphic layer to the map&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Widget from "@arcgis/core/widgets/Widget";
import MapView from "@arcgis/core/views/MapView";
import WebMap from "@arcgis/core/WebMap";
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
import Graphic from "@arcgis/core/Graphic";
import { subclass, property } from "@arcgis/core/core/accessorSupport/decorators";
import { tsx } from "@arcgis/core/widgets/support/widget";

import FeatureLayer from "@arcgis/core/layers/FeatureLayer";

@subclass("esri.widgets.SimpleWidget")
class SimpleWidget extends Widget {

    constructor(map: WebMap, mapView: MapView) {
        super();
        this.map = map;
        this.view = mapView;

    }

    @property()
    enabled: boolean = false

    @property()
    map: WebMap  //| null = null

    @property()
    view: MapView //| null = null


    render() {
        let dropdown = this.populateLayerList()
        this.onMapChange()
        // widget container
        // layer list to get all layers of the view - updates when change happens
        // meter range for query
        // execute button toggles on/of view.on click event that creates the query 
        //
        return &amp;lt;div class="groundZeroWidget"&amp;gt;
            {dropdown}
            &amp;lt;input id="queryRange" type="number" /&amp;gt;
            &amp;lt;button onclick={this.toggleQueryButton()}&amp;gt;execute&amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
    }

    //creates the list of feature layers on open and on change
    private populateLayerList() {

        console.log("populateLayerList");

        let layerList: FeatureLayer[] = [] //list of all feature layers

        this.map.allLayers.forEach((x: FeatureLayer) =&amp;gt; {
            if (x.type == "feature") {
                console.log(x.title);
                layerList.push(x) //list of layer titles
            }
        });

        function MakeItem(x: FeatureLayer) {
            return &amp;lt;option key={x}&amp;gt;{x.title}&amp;lt;/option&amp;gt;;
        };


        return &amp;lt;select id="layerTitleList" &amp;gt;{layerList.map(MakeItem)}&amp;lt;/select&amp;gt;;


    }

    private onMapChange() {

        this.map.allLayers.on("change", function (event) {
            console.log("onMapChange");
            
            // change event fires after an item has been added, moved or removed from the collection.
            // event.moved - an array of moved layers
            // event.removed - an array of removed layers
            // event.added returns an array of added layers

            // this.populateLayerList() ----------not stable yet
        })

    }

    // toggles widget active, changes button color 
    private toggleQueryButton() {
        
        console.log('toggleQueryButton');

        let layerList: __esri.Collection&amp;lt;FeatureLayer&amp;gt; | FeatureLayer[] = [] //list of all feature layers
        this.map.allLayers.forEach((x: FeatureLayer) =&amp;gt; {
            if (x.type == "feature") {
                layerList.push(x)
            }
        });

        (this.enabled) ? (this.enabled = false) : (this.enabled = true) //toggles widget active
        console.log("enabled?:" + this.enabled);
        // change button color


        this.view.on("click", (event) =&amp;gt; {
            console.log("click event: ", event.mapPoint);
            let groundZeroXY = event.mapPoint;
            if (this.enabled) {
                this.executeQuery(groundZeroXY, layerList);
            }
        });
    }
    //when active creates layer from specifications and adds it to the map 
    private executeQuery(screenPoint: __esri.MapViewScreenPoint, layerList: any[] | __esri.Collection&amp;lt;FeatureLayer&amp;gt;) {

        console.log("executeQuery");
        
        //get selected layer
        let layerTitle = (document.getElementById('layerTitleList') as HTMLSelectElement).value
        console.log(layerTitle);

        let queryLayer: FeatureLayer = layerList.find(x =&amp;gt; x.title == layerTitle);

        //get selected range
        let range = (document.getElementById('queryRange') as HTMLInputElement).value;

        console.log("range: " + range);

        let Glayer = new GraphicsLayer();

        let map = this.map

        const point = this.view.toMap(screenPoint);

        // Query the for the items within x-KM from where the user clicked for layer x
        var query = queryLayer.createQuery();
        query.geometry = point;
        query.spatialRelationship = "intersects";
        query.distance = parseInt(range);
        query.units = "meters";
        query.returnGeometry = true;
        query.outFields = ["*"];
        queryLayer.queryFeatures(query).then(function (res: __esri.FeatureSet) {
            if (res.features.length === 0) {
                console.log("no items 1st layer");
            }

            console.log(res.features);
            console.log(res.features[0]);

            let graphic: Graphic[] = res.features;


            Glayer.addMany(graphic);
            map.add(Glayer);

            if (Glayer.graphics.length === 0) {
                console.log("no featuers");
            }
        });
    }

}
export = SimpleWidget;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 15:43:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1072942#M73636</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-06-26T15:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1073529#M73665</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/440581"&gt;@litch&lt;/a&gt;&amp;nbsp;it's best to avoid setting up any state management in the render() method. One recommendation is to move any state management code (e.g. onMapChange) into the postInitialize() stage of the widget's life cycle.&amp;nbsp; You can implement &lt;FONT face="courier new,courier"&gt;postInitialize()&lt;/FONT&gt; just like you can with &lt;FONT face="courier new,courier"&gt;render()&lt;/FONT&gt;. Here's some additional Widget-related documentation you can read through, if you haven't done so already:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/custom-widget/#implement-properties-and-methods" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/custom-widget/#implement-properties-and-methods&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 00:19:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1073529#M73665</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2021-06-29T00:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1073956#M73686</link>
      <description>&lt;P&gt;Hey Andy, thank you for the answer.&lt;/P&gt;&lt;P&gt;To better understand creating widgets and what went wrong, I made a skeleton widget, a toggling button.&lt;/P&gt;&lt;P&gt;I still experience hectic behavior, while not clicking once it's still flickering "on and off".&lt;/P&gt;&lt;P&gt;how do I correctly use the toggle function?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Widget from "@arcgis/core/widgets/Widget";
import { subclass, property } from "@arcgis/core/core/accessorSupport/decorators";
import { tsx } from "@arcgis/core/widgets/support/widget";


@subclass("esri.widgets.SimpleWidget2")
class SimpleWidget2 extends Widget {
    
    @property()
    bool =  false


    toggle(){
        this.bool = !this.bool
    }

    render() {
        const {bool} = this

        return (
            &amp;lt;div &amp;gt;
                &amp;lt;button onclick={this.toggle()}&amp;gt;{bool ? "Stop" : "Start"}&amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
        );    }

}

export = SimpleWidget2;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="changing with no clicks" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/17324i2332A0D95EAE2763/image-size/large?v=v2&amp;amp;px=999" role="button" title="c2d699c4-a50d-4df8-a8e0-41d331aa51bb.jpg" alt="changing with no clicks" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;changing with no clicks&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 23:58:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1073956#M73686</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-06-29T23:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074242#M73701</link>
      <description>&lt;P&gt;Yep, getting closer. There is still state management in the render() method, you'll need to move the button click event listener code to the component.&amp;nbsp; Some other suggestions, note this is psuedo-code because I haven't tested it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Widget from "@arcgis/core/widgets/Widget";
import { subclass, property } from "@arcgis/core/core/accessorSupport/decorators";
import { tsx } from "@arcgis/core/widgets/support/widget";

@subclass("esri.widgets.SimpleWidget2")
class SimpleWidget2 extends Widget {
    
    @property()
    msg =  "test"; //to test simply assign this property a different string.

    private _toggle(){
        return this.msg;
    }

    render() {
        const testMessage = this._toggle();
        return (
            &amp;lt;div&amp;gt;
                {testMessage}
            &amp;lt;/div&amp;gt;
        );    
    }
}

export default SimpleWidget2;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 20:19:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074242#M73701</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2021-06-30T20:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074422#M73706</link>
      <description>&lt;P&gt;Just a quick follow-up, I tested the above code and it worked. Here's some more psuedo-code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;    //Add widget to component
    this.simpleWidget = new SimpleWidget2({
       container: document.createElement("div")
    });
    // Be sure to add widget to the view
    this.view.ui.add(this.simpleWidget, "bottom-right");      

    // After map initialized and widget has been added to the component
    let count = 0;
    const c = this.simpleWidget.container.addEventListener("click", () =&amp;gt; {
        this.simpleWidget.msg = "test" + this.count++;
    })&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 20:46:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074422#M73706</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2021-06-30T20:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074543#M73715</link>
      <description>&lt;P&gt;so I tested the code by myself and the string did change.&lt;/P&gt;&lt;P&gt;but the main problem I had was behavior.&lt;/P&gt;&lt;P&gt;adding a log to your code revealed that it was still calling the function multiple times without clicking.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="6d2c551e-ca2b-49b5-b29d-a266a2fbe43d.jpg" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/17451iF5CD914CC759A1B8/image-size/large?v=v2&amp;amp;px=999" role="button" title="6d2c551e-ca2b-49b5-b29d-a266a2fbe43d.jpg" alt="6d2c551e-ca2b-49b5-b29d-a266a2fbe43d.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;private _toggle(){
        console.log("test");
        return this.msg;
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;^only change I made.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also created a cleaner version of my skeleton widget:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Widget from "@arcgis/core/widgets/Widget";
import { subclass, property } from "@arcgis/core/core/accessorSupport/decorators";
import { tsx } from "@arcgis/core/widgets/support/widget";


@subclass("esri.widgets.SimpleWidget2")
class SimpleWidget2 extends Widget {
    
    @property()
    bool =  false


    private toggle(): void {
        this.bool = !this.bool;        
      }

    render() {
        const bool = this.bool
        const text = bool ? "Stop" : "Start"
        const toggle =this.toggle

        return (
            &amp;lt;div &amp;gt;
                &amp;lt;button onclick={toggle}&amp;gt;{text}&amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
        );    }

}

export = SimpleWidget2;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried a version with:&lt;/P&gt;&lt;P&gt;@property()&lt;BR /&gt;text = this.bool ? "Stop" : "Start"&lt;/P&gt;&lt;P&gt;and in the renderer:&lt;/P&gt;&lt;P&gt;const text = this.text&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;both versions didn't work.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;adding "bind={this} " which I found in Esri repos worked!&lt;/P&gt;&lt;P&gt;and this is a working sample:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import Widget from "@arcgis/core/widgets/Widget";
import { subclass, property } from "@arcgis/core/core/accessorSupport/decorators";
import { tsx } from "@arcgis/core/widgets/support/widget";


@subclass("esri.widgets.SimpleWidget2")
class SimpleWidget2 extends Widget {
    
    @property()
    bool =  false


    private toggle(): void {
        this.bool = !this.bool;
        console.log(this.bool);
      }

    render() {
        const bool = this.bool
        const text = bool ? "Stop" : "Start"
        const toggle =this.toggle

        return (
            &amp;lt;div &amp;gt;
                &amp;lt;button bind={this} onclick={toggle}&amp;gt;{text}&amp;lt;/button&amp;gt;
            &amp;lt;/div&amp;gt;
        );    }

}

export = SimpleWidget2;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;this is how I add my widgets if it matters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;view.ui.add(new SimpleWidget2(),"top-right")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id like to better understand why your code &lt;STRONG&gt;calls the function multiple times&lt;/STRONG&gt; and how can I control it,&lt;/P&gt;&lt;P&gt;in my original widget functions are supposed to create an HTML element once, toggle, query, and listen.&lt;/P&gt;&lt;P&gt;the problem is the multiple and unintentional function calling.&lt;/P&gt;&lt;P&gt;P.S I added a &lt;SPAN&gt;postInitialize() as you suggested and the listener seems to work.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 01:00:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074543#M73715</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-07-01T01:00:22Z</dc:date>
    </item>
    <item>
      <title>Re: handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074757#M73719</link>
      <description>&lt;P&gt;Hmmm, the multiple calls are most likely related to the toggle function, it shouldn't really be there. A better approach would be to remove toggleI() and any other state management/business logic from the widget and only use plain old data binding. That way the View is only used as a View. The component should handle all state management and business logic.&lt;/P&gt;&lt;P&gt;So in the widget you'd have:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;@property()
message = "Start"; //default value


render() {
   return (
     &amp;lt;div&amp;gt;{this.message}&amp;lt;/div&amp;gt;
   );
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jul 2021 15:52:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1074757#M73719</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2021-07-01T15:52:42Z</dc:date>
    </item>
    <item>
      <title>Re: handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1075523#M73732</link>
      <description>&lt;P&gt;This is the heart of my question.&lt;/P&gt;&lt;P&gt;My widget uses the maps feature layers(dynamic dropdown), this doesn't only change every app, but in some apps changes while using.&lt;/P&gt;&lt;P&gt;The data isn't static, I have a function to create it. How do I link it correctly?&lt;/P&gt;&lt;P&gt;My widget can have an on/off state while open(not destroyed just off). How can I change it if every function calls itself without control?&lt;/P&gt;</description>
      <pubDate>Sun, 04 Jul 2021 22:26:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1075523#M73732</guid>
      <dc:creator>litch</dc:creator>
      <dc:date>2021-07-04T22:26:51Z</dc:date>
    </item>
    <item>
      <title>Re: handling and rendering in a widget</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1077253#M73790</link>
      <description>&lt;P&gt;You'll need to use Angular data binding to pass data between the component class and the widget class, here's some additional info:&amp;nbsp;&lt;A href="https://angular.io/guide/two-way-binding" target="_blank" rel="noopener"&gt;https://angular.io/guide/two-way-binding&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://angular.io/guide/binding-syntax" target="_blank" rel="noopener"&gt;https://angular.io/guide/binding-syntax&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jul 2021 14:44:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/handling-and-rendering-in-a-widget/m-p/1077253#M73790</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2021-07-09T14:44:35Z</dc:date>
    </item>
  </channel>
</rss>

