Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1237] Alloy: Remove all event listeners added via view in $.destroy()

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusResolved
ResolutionFixed
Resolution Date2015-05-29T10:52:27.000+0000
Affected Version/sAlloy 1.5.1
Fix Version/sAlloy 1.7.0
ComponentsRuntime
Labelsevents, views
ReporterFokke Zandbergen
AssigneeTim Poulsen
Created2015-02-10T11:57:42.000+0000
Updated2015-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.

Comments

  1. Feon Sua Xin Miao 2015-05-29

    PR merged.
  2. Andrey Tkachenko 2015-09-04

    I have installed Alloy 1.7.6 Markup of My View:
       <Alloy>
       	<View  onClick="onClick" />
       </Alloy>
       
    After compile I found empty destroy method body:
       exports.destroy = function() {};
       
    Is it should contains unsubscribe code? http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Controller-method-destroy
  3. Fokke Zandbergen 2015-09-04

    [~falko] it looks like you're right. The $.destroy() functions should call $.removeListener(). [~k0sukey] see https://github.com/appcelerator/alloy/pull/671#issuecomment-137712880

JSON Source