jchansen/todomvc-backbone-marionette-requirejs-grunt — pull request #1 by jchansen (2014-03-28 08:48:37+00:00)
Title: Socket io integration

Integrated socket.io so changes made are synched across browers. Started by experimenting with overriding backbone.sync, but found a much simpler solution by creating a mediator/observer that listens to the events coming out of Repositories and then communicates the changes to the server.

** Notes from commit #2d25b159db37ef802d9bf8f15a221396b0bae688
The main problem with this implementation is that backbone.sync uses a
success callback in the options param to trigger the standard parsing
behavior, removing a successfully deleted model from a collection, etc.
This callback then needs to get called in the socket.on(“…”, foo)
callback. But socket.on can only be executed once, otherwise the
callbacks start stacking because they get registered every time. This
is challenging. A much easier and less over-ridingly invasive approach
is to hook into the repository, and send realtime events out each time
something of importance changes. Let backbone use the ajax structure
that works so well against the standard API, and simply send out
messages when new models are created.