<?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: Dojo Widget Scoping in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-widget-scoping/m-p/172321#M15933</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Justin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; This is the exact situation where lang.hitch comes into play.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;require: dojo/_base/lang&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14249680342145312" jivemacro_uid="_14249680342145312"&gt;&lt;P&gt;on(&lt;SPAN class="keyword"&gt;this.drawTools, &lt;SPAN class="string"&gt;"draw-complete"&lt;/SPAN&gt;, lang.hitch(this, &lt;SPAN class="keyword"&gt;this&lt;/SPAN&gt;.drawingCompleteHandler));&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Feb 2015 16:27:42 GMT</pubDate>
    <dc:creator>RobertScheitlin__GISP</dc:creator>
    <dc:date>2015-02-26T16:27:42Z</dc:date>
    <item>
      <title>Dojo Widget Scoping</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-widget-scoping/m-p/172320#M15932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm working on a reusable widget. I started with the HomeButton sample, &lt;A href="https://developers.arcgis.com/javascript/jshelp/intro_custom_dijit.html" title="https://developers.arcgis.com/javascript/jshelp/intro_custom_dijit.html" rel="nofollow noopener noreferrer" target="_blank"&gt;Create a Re-usable Widget | Guide | ArcGIS API for JavaScript&lt;/A&gt; , and am now trying to make my own. I'm getting stuck in a scoping issue though. I want to allow the user to draw a graphic and then pass that graphic back to the widget so that other components of the widget can act on the the result. So like the demo shows I have the widget referenced using the this keyword which looks like it keeps the unique widget. I can get the drawing to activate fine and the handler grabs the geometry and makes a graphic as it should but once it is passed into the handler, drawingCompleteHandler, I can't get the graphic or anything back out of the handler and using 'this' once it's in the handler function will reference the draw instead of the widget. I was thinking that there might be a way to use a promise to get the result from the handler back out to the larger widget but I'm not too familiar with using promises. I could set a global variable but then if someone create multiple instances of the widget they all end using the same global; not to mention the standard downsides to using a global variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;drawingCompleteHandler: function (evt) {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // here 'this' refers to the draw instead of the widget so I can't interact with the widget anymore
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...blah blah blah code to handle the evt result
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return graphic;
},
_init: function () {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // here 'this' refers to the widget
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on(this.drawTools, "draw-complete", &lt;SPAN style="line-height: 1.5;"&gt;this.drawingCompleteHandler&lt;/SPAN&gt;&lt;SPAN style="line-height: 1.5;"&gt;);&lt;/SPAN&gt;
&lt;SPAN style="line-height: 1.5;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/SPAN&gt;
&lt;SPAN style="line-height: 1.5;"&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:55:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-widget-scoping/m-p/172320#M15932</guid>
      <dc:creator>JustinShepard</dc:creator>
      <dc:date>2021-12-11T08:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dojo Widget Scoping</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-widget-scoping/m-p/172321#M15933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Justin,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; This is the exact situation where lang.hitch comes into play.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;require: dojo/_base/lang&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_14249680342145312" jivemacro_uid="_14249680342145312"&gt;&lt;P&gt;on(&lt;SPAN class="keyword"&gt;this.drawTools, &lt;SPAN class="string"&gt;"draw-complete"&lt;/SPAN&gt;, lang.hitch(this, &lt;SPAN class="keyword"&gt;this&lt;/SPAN&gt;.drawingCompleteHandler));&lt;/SPAN&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Feb 2015 16:27:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-widget-scoping/m-p/172321#M15933</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2015-02-26T16:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Dojo Widget Scoping</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-widget-scoping/m-p/172322#M15934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great. I'll start testing that today and let you know how it goes. Thanks for the quick response too!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Feb 2015 17:26:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/dojo-widget-scoping/m-p/172322#M15934</guid>
      <dc:creator>JustinShepard</dc:creator>
      <dc:date>2015-02-26T17:26:50Z</dc:date>
    </item>
  </channel>
</rss>

