code: function syncUpdates(modelName, array, cb) {
        cb = cb || angular.noop;
  
        /**
         * Syncs item creation/updates on 'model:save'
         */
        socket.on(modelName + ':save', function (item) {
          var index = _.findIndex(array, {_id: item._id});
          var event = 'created';
  
          // replace oldItem if it exists
          // otherwise just add item to the collection
          if (index !== -1) {
            array.splice(index, 1, item);
            event = 'updated';
          } else {
            array.push(item);
          }
  
          cb(event, item, array);
        });
  
        /**
         * Syncs removed items on 'model:remove'
         */
        socket.on(modelName + ':remove', function (item) {
          var event = 'deleted';
          _.remove(array, {_id: item._id});
          cb(event, item, array);
        });
      }
docs: Register listeners to sync an array with updates on a model
  
  Takes the array we want to sync, the model name that socket updates are sent from,
  and an optional callback function after new items are updated.
  
  @param {String} modelName
  @param {Array} array
  @param {Function} cb