Skip to content

Commit

Permalink
Fixed issue with 3.4.0s IO module
Browse files Browse the repository at this point in the history
  • Loading branch information
davglass committed Sep 7, 2011
1 parent 30858d3 commit 3a802df
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
52 changes: 45 additions & 7 deletions lib/yui3-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ YUI.add('io-nodejs', function(Y) {
send: function(uri, transactionObject, config) {
//Y.log(sys.inspect(transactionObject), 'info', 'nodeio');
//Y.log(sys.inspect(config), 'info', 'nodeio');
Y.io.xdrResponse(transactionObject, config, 'start');

Y.io.xdrResponse('start', transactionObject, config);

var urlInfo = url.parse(uri, parseQueryString=false),
p = YUI.urlInfoPort(urlInfo);
Expand Down Expand Up @@ -71,7 +71,7 @@ YUI.add('io-nodejs', function(Y) {
} else {
Y.log(socketException, 'error', 'nodeio');
}
Y.io.xdrResponse(transactionObject, config, 'failure');
Y.io.xdrResponse('failure', transactionObject, config);
});

request.addListener('response', function (response) {
Expand Down Expand Up @@ -122,9 +122,13 @@ YUI.add('io-nodejs', function(Y) {
}
//Y.log(JSON.stringify(transactionObject.c, null, 2), 'warn', 'nodeio');
//sys.print(sys.inspect(transactionObject.c));

Y.io.xdrResponse(transactionObject, config, 'complete');
Y.io.xdrResponse(transactionObject, config, ((good) ? 'success' : 'failure'));

//Hack around 3.4.0 removal of the complete event
var io = Y.io._map[transactionObject.uid];
io.complete(transactionObject, config);

//Y.io.xdrResponse('complete', transactionObject, config);
Y.io.xdrResponse(((good) ? 'success' : 'failure'), transactionObject, config);

//TODO
//Y.io.xdrResponse(transactionObject, configurationObject, 'timeout');
Expand Down Expand Up @@ -154,6 +158,7 @@ YUI.add('io-nodejs', function(Y) {
* HACK - I don't like this, but this is the only way I can intercept io calls
* and auto apply the xdr config option.
*/
/*
var _io = Y.io;
Y.io = function(url, config) {
if (!config) {
Expand All @@ -176,6 +181,39 @@ YUI.add('io-nodejs', function(Y) {
Y.io.header = function(name, value) {
_headers[name] = value;
};
var _io = Y.io;
Y.io = function(u, c) {
c.xdr = { use: 'nodejs' };
var o = Y.io._map['io:0'] || new Y.IO();
o.transport(NodeTransport);
console.error('Creating IO instance: ', Object.keys(o));
console.error('Creating IO instance2: ', Object.keys(new Y.IO()));
return o.send.apply(o, [u, c]);
};
for (var i in _io) {
Y.io[i] = _io[i];
}
*/

var _send = Y.IO.prototype.send;

Y.IO.prototype.send = function(url, config) {
if (!config) {
config = {};
}
config.xdr = { use: 'nodejs' };
this._transport['nodejs'] = NodeTransport.src;
return _send.call(this, url, config);
};

var _headers = {};
Y.io.header = function(name, value) {
_headers[name] = value;
};


}, 'NODE', { requires: ['io', 'io-xdr'], after: ['io-xdr'] });
}, 'NODE', { requires: ['dom-base', 'io-base', 'io-xdr'] });

3 changes: 2 additions & 1 deletion lib/yui3-yui3.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ var configureYUI = function(c) {
},
'io-nodejs': {
fullpath: __dirname + '/yui3-io.js',
requires: ['dom-base'], //To ensure we get JSDOM
condition: {
when: 'after',
trigger: 'io',
trigger: 'io-base',
test: function() {
return true;
}
Expand Down

0 comments on commit 3a802df

Please sign in to comment.