jashkenas/backbone — pull request #2918 by bytasv (2013-12-13 13:08:48+00:00)
Title: Add saved and fetched events for more flexible requests handling

Added two simple events that allow to recognize when model was fetched or saved to backend.

Simple usecase:

I want to display notification for user after successfully saving form: the only possible way is to call model.save method with additional options i.e.: model.save(null, {isSave: true}) and then listen model's "sync" event and handle callback checking if options argument has truthy "isSave" value. I couldn't find any other possible ways without specifying options argument. Also this approach also stinks because you need to implement something like "saveData" method which will make that save call with correct arguments.

Another usecase:
I want to render model values only when it is retrieved from the server, same technique - call fetch with options param and then check, again ugly...

Now with this update I can do:

model.on('saved', displaySuccessNotification);

or

model.on('fetched', renderModelValues);

No overhead, no breaking API changes, only very small additions that would allow easier development for a lot of people.