     if not model.collection
       model.collection = this
 
-
     @add model, options
     return model
 
-
   fetch: (options={}) ->
+    # Fetch can be called only once
+    if @fetched
+      return cb()
+    @fetched = true
+
+    # Convert Backbone.js style object callback to Node.js style callback
+    callbackWrapper = (err) =>
+      if err
+        options?.error? err
+      else
+        @connected = true
+        @_flushAddingQueue()
+        @trigger "connect", this
+        options?.success?()
 
     if options.sharejsDoc
       @_syncDoc = options.sharejsDoc


S4 = -> (((1 + Math.random()) * 65536) | 0).toString(16).substring(1)

# Convert Backone.js style options object based callbacks to Node.js style
# single function callbacks used in ShareJS
optionsCbToNodeCb = (options) -> (err) ->
  if err
    options?.error?()
  else
    options?.success?()


Backbone.sync = (method, model, options) ->
  console.log "METHOD", method

  # Call options.success() callback to trigger destroy event which triggers
  # synchronization to other browsers.
  if method is "delete"



  add: (models, options) ->

    if not models or models.length is 0
      return this

    if not _.isArray models
      models = [ models ]

    if not @fetched
      while model = models.shift()
        debugger
        console.log "Adding #{ model.get "name" } to queue"
        @_addingQueue.push model
      return this

    for m in models
      @_sendModelAdd m, options

    super

