Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

widget.connect to widget.on handle cleanup #18

Open
mmaxwell opened this issue Apr 1, 2013 · 1 comment
Open

widget.connect to widget.on handle cleanup #18

mmaxwell opened this issue Apr 1, 2013 · 1 comment
Labels

Comments

@mmaxwell
Copy link
Contributor

mmaxwell commented Apr 1, 2013

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
Copy link

wkeese commented Apr 6, 2013

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", ...))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants