0

I'm trying to understand when to use events in the view vs in the models or collections. From what I understand now:

  1. events in the UI that made by the user - should be in the view's "event" method.

  2. for listening to changes in the model and re-render the view of it, I will place a listen event in the initialize method of the view.

  3. to what exactly do I listen in the initialize method of models ?

  4. what else should I know about this stuff? what about listening to changes in collections and routers ?

Thanks.

Daniel
  • 1,562
  • 3
  • 22
  • 34

1 Answers1

1

Basically you will listen to model or collection changes so you can re-render parts of your view. So think of the the todo example. You have a text box and a list of todos. Now when you submit a todo, that todo gets added to the collection. If you were not listening for changes on the todo list, the list would remain static. So therefore when a new todo gets added to the collection, you need to re-render the todo-list-view, and you do that by listening for changes to the collection. I hope that makes sense.

Another example would be listening to changes on the router. On route-change, you could for example update your navigation class to show you which navigation element to highlight. Therefore the correct navigation property will be highlighted even when the user enters the url in the address bar.

TYRONEMICHAEL
  • 4,174
  • 4
  • 30
  • 47