Reputation: 88367
If I listened to an event using .listenTo()
, how do I unbind it?
In some code I am working on, I have something like:
class Something extends Marionette.CompositeView
initialize: ->
...
// listen to an event of a static object
@listenTo Something.dateRange, DateRange.EVENT_CHANGED, @_update
The problem appears to be when I switch between views, this event is not unbound, thus, it gets triggered more and more times as the view is reinitalized. Shouldn't Marionette unbind such events? If it doesn't, how do whats the reverse of listenTo
? I guess I just put that in onBeforeClose
Upvotes: 1
Views: 2711
Reputation: 88367
Oh I think I got it ... its stopListening
from Backbone.Events
not Marionette. I was looking in the Marionette docs, the wrong place. The relevant information is within the Backbone Events docs.
Upvotes: 3
Reputation: 73
You can also use listenToOnce
. Now the event will only trigger ones if you initialize the class.
Upvotes: 1