       @collections[collection].push record
     record
 
-
 # Export to global namespace
 #######################################
 @App = {} unless @App

        _.extend(data.record, packet.data)

    update_many: (packet, collection) ->
      local_collection = @collections[collection || packet.collection]
      _.each packet.data, (fields) ->
        record = _.findIndex(local_collection, (r) -> r.id == fields.id)
        if record>=0
          _.extend(local_collection[record], fields)
        else
          local_collection.push(fields)

    destroy: (packet, collection) ->
      data = processPacketHelper(packet, collection)

  # Private methods
  #####################################

  # Default callbacks for internal storage of received packets
  # Need to set include_initial: true in broadcasting options
  class DefaultCallbacks
    constructor: (@collections) ->

    # Helper function
    processPacketHelper = (packet, collection) ->
      index = -1
      record = null

      local_collection = @collections[collection || packet.collection]
      if !local_collection
        console.warn("[update_many]: Collection #{collection_name} doesn't exist")
      else
        index = _.find(local_collection, (record) -> record.id == packet.id)
        if (index >= 0)
          record = local_collection[index]

      return {
        collection: local_collection
        index: index
        record: record
      }

    # Callbacks
    ##################################################

    initialize: (collection) ->
      @collections[collection] = []

    collection_remove: (packet, collection) ->
      console.warn 'Method not implemented: collection_remove '
