marionettejs/backbone.radio

Automated cleanup of Commands and Requests?

Open

#117 ouverte le 29 juil. 2014

Voir sur GitHub
 (22 commentaires) (0 réactions) (1 assigné)JavaScript (53 forks)batch import
enhancementhelp wanted

Métriques du dépôt

Stars
 (494 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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?

Guide contributeur