marionettejs/backbone.radio

Automated cleanup of Commands and Requests?

Open

#117 geöffnet am 29. Juli 2014

Auf GitHub ansehen
 (22 Kommentare) (0 Reaktionen) (1 zugewiesene Person)JavaScript (53 Forks)batch import
enhancementhelp wanted

Repository-Metriken

Stars
 (494 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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?

Contributor Guide