janmonschke / backbone-couchdb

A couchdb connector for backbone with support for real time changes.

Home Page:http://janmonschke.com/projects/backbone-couchdb.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Backbone.sync() parameter signature

gbluma opened this issue · comments

Found a small bug (or potential bug depending on the version of backbone.js used).

The bug relates to Backbone.sync() having a different parameter signature for the overridden function. Here is the signature of the original function (backbone.js):

Backbone.sync = function(method, model, success, error) {

And the override (backbone-couchdb.js):

// Override the standard sync method.
Backbone.sync = function(method, model, options) {

Notice the "options" vs "success, error"

Solution: Here, I made a few updates to the overridden function to support the change in "options" (backbone-couchdb.js):

// Override the standard sync method.
Backbone.sync = function(method, model, success, error) {
    if(method == "create" || method == "update"){
        Backbone.couchConnector.create(model, success, error);
    }else if(method == "read"){
        // Decide whether to read a whole collection or just one specific model
        if(model.collection)
            Backbone.couchConnector.readModel(model, success, error);
        else
            Backbone.couchConnector.readCollection(model, success, error);
    }else if(method == "delete"){
        Backbone.couchConnector.del(model, success, error);
    }

    // Activate real time changes feed
    if(Backbone.couchConnector.enableChanges && !Backbone.couchConnector.changesFeed){
         Backbone.couchConnector._changes(model);
    }   
}

Hi, this has already been addressed and fixed in this issue:
https://github.com/janmonschke/backbone-couchdb/issues/closed#issue/4