Skip to content

Commit

Permalink
[JX.Request] Add "open" event
Browse files Browse the repository at this point in the history
Summary:
Evan was right, it makes sense to have an event that people can listen to to
screw with the transport. Turns out
that many of the transport properties can't be set until after open() has been
called on it, so we need another
hook.

I like this approach more now than I did before because we pass the JX.Request
instance into the callback
instead of the raw XHR. The user can now call getTransport() himself.

Test Plan:
in firebug:

  var r = new JX.Request('test/');
  r.listen('open', function(req) { req.getTransport().withCredentials = true;
});
  r.send();
  r.getTransport()

and inspected the transport. withCredentials was set to true.

Reviewed By: aran
Reviewers: tomo, epriestley, aran
CC: aran, nikolay
Differential Revision: 348
  • Loading branch information
mroch committed May 26, 2011
1 parent 140e036 commit 13c8900
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/Request.js
Expand Up @@ -18,7 +18,7 @@ JX.install('Request', {
} }
}, },


events : ['send', 'done', 'error', 'finally'], events : ['open', 'send', 'done', 'error', 'finally'],


members : { members : {


Expand Down Expand Up @@ -77,8 +77,6 @@ JX.install('Request', {
uri += ((uri.indexOf('?') === -1) ? '?' : '&') + q; uri += ((uri.indexOf('?') === -1) ? '?' : '&') + q;
} }


this.invoke('send', this);

if (this.getTimeout()) { if (this.getTimeout()) {
this._timer = JX.defer( this._timer = JX.defer(
JX.bind( JX.bind(
Expand All @@ -90,6 +88,10 @@ JX.install('Request', {


xport.open(method, uri, true); xport.open(method, uri, true);


// Must happen after xport.open so that listeners can modify the transport
// Some transport properties can only be set after the transport is open
this.invoke('open', this);

if (__DEV__) { if (__DEV__) {
if (this.getFile()) { if (this.getFile()) {
if (method != 'POST') { if (method != 'POST') {
Expand All @@ -106,6 +108,8 @@ JX.install('Request', {
} }
} }


this.invoke('send', this);

if (method == 'POST') { if (method == 'POST') {
if (this.getFile()) { if (this.getFile()) {
xport.send(this.getFile()); xport.send(this.getFile());
Expand Down

0 comments on commit 13c8900

Please sign in to comment.