jQuery-Parse icon indicating copy to clipboard operation
jQuery-Parse copied to clipboard

parse.get synchronous

Open arvindstutzen opened this issue 11 years ago • 3 comments

Is it possible have parse.get function as synchronous one ?

arvindstutzen avatar Feb 02 '14 13:02 arvindstutzen

Right now, there is no way to override the $.ajax request object through parse.get. However, parse.get does return the $.Deferred object from $.ajax. So I would suggest just using

var req = $.parse.get('Class');
 req.done(doSomethig);
 req.done(doAnotherThing)

You could make a really easy step system like this..

  var step = function(cb){
    req.done(cb);
};

Also, take a look at how Jasmine does runs, waitsFor, runs. This is a great way of handling synchronous/async behavior.

What are you trying to build? Would love to give advice if needed. Be well.

srhyne avatar Feb 03 '14 16:02 srhyne

Hi There, I've tried to do just that var req = $.parse.get('Class'); req.done(doSomethig); req.done(doAnotherThing)

It keeps telling me that done() is undefined. So I thought maybe my jQ library was old but even complete() doesn't work.

Any ideas?

abusu-noggin avatar Mar 26 '15 01:03 abusu-noggin

@abusu-noggin I'm sorry, I was mistaken. The $.parse.get does not return a $.Deferred object. It just returns $.parse. Instead you need to pase $.parse.get('Class', callback, error)

However, here's a nice wrapper for a getting a promise for a get request.

$.parse.getPromise = function(class){
  var dfd;

    $.parse.get(class, function(data){
       dfd.resolve(data);
    }, function(data){
       dfd.reject(data);
    });

    return dfd;
}

srhyne avatar Mar 27 '15 12:03 srhyne