alerts controller of particular event 2 Controller Updates Model 3 Model alerts view that it has changed. 4 View grabs model data and updates itself. 5
View alerts controller of particular event 2 Controller Updates Model 3 Model alerts view that it has changed. 4 View grabs model data and updates itself. 5 View 2
my function view.foo(). The change happens, so the model calls view.foo(). 1 2 3 The view grabs the changed data from the model and updates itself. View-Model Relationship
} /* * view tells model that if “change” happens, * then call view’s render function */ model.subscribe(“change”,view.render); /* * The “change” happens, so the model alerts * any observers of “change” */ model.notify(“change”); 1 2 3 Observer Pattern – Basic Use
would //cause function2 and function3 to be called. {“abritraryString2” : [function2, function3] }, //model.subscribe(“arbitraryString3”,function4) //would add function4 to this list {“abritraryString3” : [function3] }, //model.subscribe(“arbitraryString4”,function1) //would add a new member to the events array ]; Observer Pattern -- Internals
up as tangled piles of jQuery selectors and callbacks, all trying frantically to keep data in sync between the HTML UI, your JavaScript logic, and the database on your server.” Jeremy Ashkenas, Creator of Backbone.js