Automated cleanup of Commands and Requests?
#117 opened on Jul 29, 2014
Description
See: http://backbonejs.org/#Events-listenTo
In the case of Backbone's eventing system, listeners are registered on objects and cleaned up automatically on destruction. Such a feature would be a really nice addition to Backbone.Radio, removing the work involved in managing clean-up of every registered event, command, and request handler.
For example, in a view that needs to exchange information with a flash player:
var SomeView = Backbone.View.extend({
initialize: function() {
var flashChannel = Backbone.Radio.channel('flash');
this.listenTo(flashChannel, 'tick', this.onTick);
this.comply(flashChannel, 'play', this.play);
this.reply(flashChannel, 'currentTime', this.currentTime);
},
onTick: ...
play: ...
currentTime: ...
});
If it simplifies matters, perhaps when needing to hand a channel in as an argument the functions can be given new names that indicate the intention to register them for later destruction - complyWith and replyTo, to go along with listenTo.
Lastly, we could wrap the remove function to include stopComplying and stopReplying functions, in addition to stopListening.
Thoughts?