Select to view content in your preferred language

custom widget - the task and how to use: this.own, and digit/_WidgetsInTemplateMixin

1322
1
Jump to solution
07-16-2020 01:33 PM
MichaelLev
Frequent Contributor

I am relatively new to ArcGIS Web AppBuilder (Developer Edition) 2.16

in last 2 months I've written several custom widgets,

yet there are 3 areas I feel I have not enough knowledge:

1. When do I need to do this.own and what are the parameters

        I learned that this.own is used to prevent memory leak,

        but I don't know when it is needed and when it is not needed, and the meaning of its parameters.

2. When do I need to use dijit/_WidgetsInTemplateMixin and what is the usage function of postMixInProperties: function() {...}

        I learned that postMixInProperties is called very early,

        but I don't know exactly why it is needed at all,

        and if there are cases where dijit/_WidgetsInTemplateMixin is needed

        but postMixInProperties function is not needed.

3. I'd like to get a little comprehensive explanation about what issues should be handled in each of the functions:

postCreate, startup, and onOpen, since when I write new custom widgets, sometimes I am not sure what type of tasks to put in each, e.g. where to put this.sceneView.when(){...} and similar things that refer viewModels, graphics etc..

Help will be greatly appreciated.

 

Michael

1 Solution

Accepted Solutions
HarishPalaniappan
Regular Contributor

At a high level,

this.own : The own function is defined in dijit/Destroyable, which is a base of dijit/_WidgetBase and thus most widgets.

Use : dijit/Destroyable is used to track handles of an instance, and then destroy them when the instance is destroyed.

The application must call destroy() on the instance in order to release the handles.

Links :

http://dojotoolkit.org/reference-guide/1.8/dijit/Destroyable.html

http://dojotoolkit.org/reference-guide/1.8/dojo/Evented.html

When do I need to use dijit/_WidgetsInTemplateMixin:

When using this template in a directly extended widget class, you will need to mixin dijit._WidgetsInTemplateMixin in addition to dijit._TemplatedMixin.

Note that dijit.Declaration-based widget classes automatically include dijit._WidgetsInTemplateMixin.

Links :

https://dojotoolkit.org/api/?qs=1.10/dijit/_WidgetsInTemplateMixin

https://dojotoolkit.org/reference-guide/1.10/dijit/_WidgetsInTemplateMixin.html

PostCreate() , startUp() and onOpen :

PostCreate and startUp function are used to initialize the widget only for the first time when widget comes into role in application.

onOpen() function is used to open widget whenever required and onOpen() function is executed with _openHander of widget to set several  related properties and state of widget.

View solution in original post

1 Reply
HarishPalaniappan
Regular Contributor

At a high level,

this.own : The own function is defined in dijit/Destroyable, which is a base of dijit/_WidgetBase and thus most widgets.

Use : dijit/Destroyable is used to track handles of an instance, and then destroy them when the instance is destroyed.

The application must call destroy() on the instance in order to release the handles.

Links :

http://dojotoolkit.org/reference-guide/1.8/dijit/Destroyable.html

http://dojotoolkit.org/reference-guide/1.8/dojo/Evented.html

When do I need to use dijit/_WidgetsInTemplateMixin:

When using this template in a directly extended widget class, you will need to mixin dijit._WidgetsInTemplateMixin in addition to dijit._TemplatedMixin.

Note that dijit.Declaration-based widget classes automatically include dijit._WidgetsInTemplateMixin.

Links :

https://dojotoolkit.org/api/?qs=1.10/dijit/_WidgetsInTemplateMixin

https://dojotoolkit.org/reference-guide/1.10/dijit/_WidgetsInTemplateMixin.html

PostCreate() , startUp() and onOpen :

PostCreate and startUp function are used to initialize the widget only for the first time when widget comes into role in application.

onOpen() function is used to open widget whenever required and onOpen() function is executed with _openHander of widget to set several  related properties and state of widget.