pusher/backpusher — Issue #1: Overriding Backbone.sync causes success/error callbacks to not fire
Author: gitt
Created: 2011-10-24 17:54:59+00:00
State: open

I noticed today that when including backpusher.js, which override Backbone.sync, that my success/error callbacks don't fire on save(). Another issue, is that when save() is called, the model isn't synced with the data in the database.

Consider the following:

``` javascript
$ ->
class App.Views.ProjectModal extends Backbone.View
id : '#project_modal'
className : 'modal'
template : JST['templates/modals/project']

events:
"submit form" : "submit"
"click a.cancel" : "cancel"

initialize: ->
_.bindAll(@, 'render', 'submit', 'cancel')
@render()

render: ->
$('body').append(
$(@el).html(
@template({
model : @model
})
)
)

$.blockUI({
message : $(@el)
})

submit: (e) ->
e.preventDefault()
@model.save(
{ name : $(e.currentTarget).find('[name=name]').val() }
{
success: (model, response) ->
console.log "Success!"
error: (model, response) ->
console.log "Error!"
}
)

$.unblockUI({
onUnblock: =>
@remove()
})

cancel: (e) ->
e.preventDefault()
$.unblockUI({
onUnblock: =>
@remove()
})
```

Without backpusher, the model is synced, and the success callback fires. With backpusher, this doesn't happen.