marionettejs/backbone.radio

Automated cleanup of Commands and Requests?

Open

#117 aperta il 29 lug 2014

Vedi su GitHub
 (22 commenti) (0 reazioni) (1 assegnatario)JavaScript (53 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (494 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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?

Guida contributor