Skip to content

Commit

Permalink
fixes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
janmonschke committed Jan 10, 2012
1 parent 19e77b4 commit f1e41cb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
12 changes: 12 additions & 0 deletions backbone-couchdb.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ Backbone.couch_connector = con =
for doc in data.rows
_temp.push doc.value
opts.success _temp
opts.complete()
error : ->
opts.error()
opts.complete()

# delete keys if a custom view is requested but no custom keys
if coll.db? and coll.db.view? and not coll.db.keys?
Expand All @@ -83,8 +85,10 @@ Backbone.couch_connector = con =
@helpers.make_db().openDoc model.id,
success : (doc) ->
opts.success(doc)
opts.complete()
error : ->
opts.error()
opts.complete()

# Creates a model in the db
create : (model, opts) ->
Expand All @@ -96,8 +100,10 @@ Backbone.couch_connector = con =
opts.success
_id : doc.id
_rev : doc.rev
opts.complete()
error : ->
opts.error()
opts.complete()

# jquery.couch.js uses the same method for updating as it uses for creating a document, so we can use the `create` method here. ###
update : (model, opts) ->
Expand All @@ -112,11 +118,17 @@ Backbone.couch_connector = con =
if e == "deleted"
# The doc does no longer exist on the server
opts.success()
opts.complete()
else
opts.error()
opts.complete()

# Overriding the sync method here to make the connector work ###
Backbone.sync = (method, model, opts) ->
opts.success ?= ->
opts.error ?= ->
opts.complete ?= ->

switch method
when "read" then con.read model, opts
when "create" then con.create model, opts
Expand Down
30 changes: 21 additions & 9 deletions backbone-couchdb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f1e41cb

Please sign in to comment.