srhyne / jQuery-Parse

An AJAX wrapper for the Parse.com REST API
212 stars 31 forks source link

parse.get synchronous #16

Open arvindstutzen opened 10 years ago

arvindstutzen commented 10 years ago

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

srhyne commented 10 years ago

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.

abusu-noggin commented 9 years ago

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?

srhyne commented 9 years ago

@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;
}