[ALOY-1237] Alloy: Remove all event listeners added via view in $.destroy()
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Low |
Status | Resolved |
Resolution | Fixed |
Resolution Date | 2015-05-29T10:52:27.000+0000 |
Affected Version/s | Alloy 1.5.1 |
Fix Version/s | Alloy 1.7.0 |
Components | Runtime |
Labels | events, views |
Reporter | Fokke Zandbergen |
Assignee | Tim Poulsen |
Created | 2015-02-10T11:57:42.000+0000 |
Updated | 2015-09-16T06:30:08.000+0000 |
Description
Too make it easier for developers to clean up the event listeners they've added via the XML view (
onClick
and other attributes), could we make it so that if you add an event listener that way, that it would also be removed in the $.destroy()
method?
The developer would still be responsible for calling that method and for removing listeners he added in the controller, but it would align nicely with the current behaviour of the method where it also cleans up a listener added via the view, which is for the <Collection>
or <Model
> tag.
For reference:
https://github.com/appcelerator/alloy/blob/master/test/apps/basics/markup_events/_generated/ios/alloy/controllers/index.js#L44-L49
Perhaps the __defers
object could be used for this in some way?
We could even go as far as extending the Backbone $.listenTo()
method that if its first argument is a proxy, then it would both pass it on to that proxies' addEventListener
method and queue it for removal in $.destroy
at the same time.
PR merged.
I have installed Alloy 1.7.6 Markup of My View:
After compile I found empty destroy method body:
Is it should contains unsubscribe code? http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Controller-method-destroy
[~falko] it looks like you're right. The
$.destroy()
functions should call$.removeListener()
. [~k0sukey] see https://github.com/appcelerator/alloy/pull/671#issuecomment-137712880