Backbone listenTo()

If you look at the docs (as of today, that is), for the listenTo() method on www.backbonejs.org you'll see that it says it takes three params: the object to listen to, the event to listen for, and the callback to fire when the object triggers the event. But apparently you can also do this, so that you can listen for more than one event on the object:

 

 

view.listenTo(collection,{
'reset': view.render,
'change': view.render
});

 


Consider these variations of listening for events ('this' is a view)

1. this.model.on('change', this.someCallback);

vs.

2. this.listenTo(this.model, 'change', this.someCallback);

In case 1, the view will not get garbage collected because the model has a reference to it.
In case 2, when remove() is called on the view, it will remove the listener on the model so that the view can be freed from memory
BUT don't forget to call remove() on the view.

 

Here are a few links that are related:

Backbone - memory leaks

Backbone - common pitfalls

 

 

Add a Comment...

 

Comments

After alâ¼, stocks Érе on sale thеse Éays аnd history sÒºows that eventually the market wÑll recover. Тhey may pоssibly charge Õ£uite much lesws fßr i - Phone tÐ¾Ö lure Ò¯â²u and might also returnn thᥱ i - Phone withÑn 24 hοurs. AÑk youгself: What kÑnd of repaqir sop Ôoesn't ɦave the screens they neᥱd in stock, oг it Ñs not capable of ordeering it wÑthout yοu leaving a deposit. - 9/12/2016

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil": captchas recognition of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another size-types of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? You can find a lot of impessive videos about XEvil in YouTube - 7/22/2017

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil": captchas solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another categories of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? You can find a lot of demo videos about XEvil in YouTube. See - 7/22/2017

Revolutional update of SEO/SMM software "XRumer 16.0 + XEvil 3.0": captchas solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another subtypes of captchas, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? There are a lot of impessive videos about XEvil in YouTube. - 7/22/2017

Revolutional update of SEO/SMM package "XRumer 16.0 + XEvil 3.0": captcha solution of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another subtypes of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other programms. Interested? You can find a lot of demo videos about XEvil in YouTube. Go - 7/21/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil": captcha regignizing of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another subtypes of captchas, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM programms: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? There are a lot of introducing videos about XEvil in YouTube. - 7/18/2017

Absolutely NEW update of SEO/SMM package "XRumer 16.0 + XEvil 3.0": captcha solving of Google, Facebook, Bing, Hotmail, SolveMedia, Yandex, and more than 8400 another types of captcha, with highest precision (80..100%) and highest speed (100 img per second). You can connect XEvil 3.0 to all most popular SEO/SMM software: XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software. Interested? There are a lot of impessive videos about XEvil in YouTube. Good - 7/14/2017

I see your website needs some unique articles. Writing manually is time consuming, but there is solution for this. Just search for: Masquro's strategies - 3/18/2017

Creditors cuгrently don't Ç¥ive mÕ½ch leeway foг debtors whß gets behind on thеir own bills. Thewre aгe strategies including, but arre noot limited ÆÊ, short sales, loan mitigation, lan forgiveness аnd morе. Înce a purchase Örder for sale (including а purchase for possession) оr an investment fÖr possession Ñs ßbtained, а warrant for eviction iÑ pretty straightforward. - 12/31/2016