Nowhere. Events have nothing to do with MVC.
Patterns are best practices for a specific solution
#Patterns are best practices for a specific solution FirstFirst of, read my rant on MVC: http://www.sitepoint.com/mvc-problem-solution/
MVC is a pattern that helps us in seperating our display, domain logic and data representation. Thats it. Nothing more.
It doesn't say anything about events or observers. Neither does it help us save the world.
MVC comunication
##MVC comunication MVCMVC states that a Controler updates a model, The Model updates the view and the view triggers the Controller.
It does however not say how this should happen. Should the Model be passed a view that it then updates. Maybe, maybe not. MVC doesn't care.
Because we are using JavaScript, we have however a very strong tool to solve this communication between the Model, view and controller; The event system.
Our Model-View communication could look like this:
model.on('update', function(updatedData) {
view.update(updatedData);
});
This is called the Observer pattern. The anonymous function is the observer that observers the model. Here, the model notifies all registered observers of a change.
Or you could go for an event notifier. where you add notifiers and listeners:
controler.prototype.changeModelName = function() {
myEventService.notify('model.update', {'data':{'name':'myNewName'}});
};
myEventService.listenTo('model.update', function(event){
model.update(event.data);
});
myEventService.listenTo('model.update', function(event){
view.update(event.data);
});
Or some other approach. MVC doesn't care.