SitePen / dojo-amd-converter

A legacy dojo to AMD conversion utility.
Other
11 stars 5 forks source link

widget.connect to widget.on handle cleanup #18

Open mmaxwell opened 11 years ago

mmaxwell commented 11 years ago

widget.connect was smart enough to remember the handles created via that call and tear them down when widget is destroyed. widget.on does not have the same behavior so we should be tearing down those connections somehow - maybe via widget.own or maybe by fixing dijit to do it automatically. see http://bugs.dojotoolkit.org/ticket/16219 for the bug in dijit to have it fixed

wkeese commented 11 years ago

Note that widget.connect() is documented as a protected method, to be used inside widgets, for example:

 this.connect(this.domNode, "onclick", "_onClick");

Correct usages of this.connect(...) should be remapped to this.own(on(...)), ex:

this.own(on(this.domNode, "click", lang.hitch(this, "_onClick"));

For incorrect usages of widget.connect(), where external code uses it to monitor events within a widget, like it says in http://bugs.dojotoolkit.org/ticket/16219 there's no need to worry about teardown. For example:

myWidget.connect(myWidget, "onClick", myFunction);

is fine to convert to:

myWidget.on("click", myFunction);

That doesn't work in all cases though, like when the first argument to connect is different than "myWidget", or the target method ("onClick" in the above example) doesn't start with "on". In those cases you'd want something like:

myWidget.own(aspect.after(foo, "bar", ...))

or if the target is a DOMNode then:

myWidget.own(on(myNode, "click", ...))