0

I am having an issue trying to get called a success callback after fetching a collection. Here is the code from the collection, the problem is excuting executeLongPolling

(function() {
window.StatusCollection = Backbone.Collection.extend({
    longPolling : false,
    intervalSeconds : 20,
    model: Status,
    url: function(){
        return this.project.id + 'statuses/';
    },
    initialize : function(){
        _.bindAll(this);
    },
    startLongPolling : function(invervalSeconds){
        this.longPolling = true;
        if( invervalSeconds ){
            this.invervalSeconds = invervalSeconds;
        }
        this.executeLongPolling();
    },
    stopLongPolling : function(){
        this.longPolling = false;
    },
    executeLongPolling : function(){
        var that = this;
        this.fetch({
            success : function(collection, response, options) {
                that.onFetch();
            }
        });
    },
    onFetch : function () {
        if( this.longPolling ){
            setTimeout(this.executeLongPolling, 1000 * this.intervalSeconds);
        }
    }
}); })();

Surprisingly, when I add the update option it works and the line that.onFetch() is called:

executeLongPolling : function(){
        var that = this;
        this.fetch({ update: true,
            success : function(collection, response, options) {
                that.onFetch();
            }
        });
    },

I am using backbone-0.9.10. and backbone-relational-0.7.0

Any ideas what's wrong? Thanks!

Markinhos
  • 736
  • 1
  • 6
  • 13
  • Can you put a breakpoint in Backbone.sync and step through it? You might be able to see what is coming back from the server and why success is not called. – Paul Hoenecke Jan 29 '13 at 01:41
  • 1
    Also, add an error handler next to your success handler and see if there is some error happening. – Paul Hoenecke Jan 29 '13 at 01:51
  • As Paul said, you should put an error handler after the success handler. Then put a breakpoint in there. I had the same problem because my JSON response was malformed. – jasop Mar 25 '13 at 07:59

1 Answers1

0

Came across your issue while looking for solution to my issue where just adding to my collection(I don't use fetch) seems to be broken after upgrading to 0.9.10 from 0.9.2 Anywho, just glancing at your question, could have something to do with fetch having changed in 0.9.10 Look at these:

Backbone throwing collection[method] function error https://github.com/addyosmani/backbone.paginator/issues/134

OR perhaps the fact that Backbone-relational isn't fully functional with 0.9.10 yet https://github.com/PaulUithol/backbone-tastypie/pull/25

Community
  • 1
  • 1
snowleopard
  • 781
  • 3
  • 13
  • 36