TheSmiths-Widgets / ts.httprequest

[unmaintained] Request library creates and handles HTTP request using Titanium's HTTPClient.
14 stars 3 forks source link

Pass more parameters? #8

Closed DouglasHennrich closed 8 years ago

DouglasHennrich commented 8 years ago

There's a way to pass more parameters? I want to pass some control variables to be handle on success of my httprequest, but now I'm only getting the response of the httprequest. Maybe something like:

function handleSuccess(response, options){
    if(options.something) //
};

new Alloy.Globals.HTTPRequest({
        method: "POST"
      , url: config.url + 'consulta_todos.php'
      , data: _params
      , options: { something: true }
}).then(handleSuccess).catch(handleError);

Thanks

PierreGUI commented 8 years ago

Yo! That's not possible, and is not a feature I will add. What about binding a context?

function handleSuccess(response){
    if(this.something) //
};

new Alloy.Globals.HTTPRequest({
        method: "POST",
        url: config.url + 'consulta_todos.php',
        data: _params
})
    .then(handleSuccess.bind({ something: true }))
    .catch(handleError);
DouglasHennrich commented 8 years ago

never use promises before... if you say it work I will give a try =P another question... to catch the onloadprogress how should I do ? An .then(..) before handleSuccess ? Thanks

PierreGUI commented 8 years ago

Binding a context is pure javascript, not specific to Promises ;)

About the progress handler, it's indeed a good question because there's no way to use promise handler yet (not in Promises A+ specs...). So you'll have to give the progress handler as a parameter:

function progressHandler(progress){
    Ti.API.info(progress);
};

new Alloy.Globals.HTTPRequest({
    method, url, data,
    progress: progressHandler
})
    .then(handleSuccess)
    .catch(handleError);
DouglasHennrich commented 8 years ago

Thaanks dude! :D bind work by the way