Permalink
Browse files

use 'on' instead of 'addListener'

  • Loading branch information...
1 parent 7b65530 commit eacb3516bcb4b0451debd9359b9f4d217bb97f5c cloudhead committed Aug 12, 2010
Showing with 12 additions and 12 deletions.
  1. +12 −12 lib/cradle.js
View
@@ -90,16 +90,16 @@ cradle.Connection.prototype.rawRequest = function (method, path, options, data,
if (data && data.addListener) { headers['Transfer-Encoding'] = 'chunked' }
- request.addListener('response', function (res) {
+ request.on('response', function (res) {
promise.emit('response', res);
- res.addListener('data', function (chunk) { promise.emit('data', chunk) });
- res.addListener('end', function () { promise.emit('end') });
+ res.on('data', function (chunk) { promise.emit('data', chunk) });
+ res.on('end', function () { promise.emit('end') });
});
if (data) {
- if(data.addListener) {
- data.addListener('data', function (chunk) { request.write(chunk) });
- data.addListener('end', function () { request.end() });
+ if (data.addListener) {
+ data.on('data', function (chunk) { request.write(chunk) });
+ data.on('end', function () { request.end() });
} else {
request.write(data, 'utf8');
request.end();
@@ -148,13 +148,13 @@ cradle.Connection.prototype.request = function (method, path, /* [options], [dat
// Initialize the request, send the body, and finally,
// dispatch the request.
//
- request.addListener('response', function (res) {
+ request.on('response', function (res) {
var body = [];
res.setEncoding('utf8');
- res.addListener('data', function (chunk) {
+ res.on('data', function (chunk) {
chunk && body.push(chunk);
- }).addListener('end', function () {
+ }).on('end', function () {
var obj, response;
if (method === 'HEAD') {
@@ -399,9 +399,9 @@ cradle.Connection.prototype.database = function (name) {
headers['Content-Type'] = contentType;
that.rawRequest('PUT', pathname, rev, dataOrStream, headers)
- .addListener('response', function (res) { resHeaders = { status: res.statusCode } })
- .addListener('data', function (chunk) { body += chunk })
- .addListener('end', function () {
+ .on('response', function (res) { resHeaders = { status: res.statusCode } })
+ .on('data', function (chunk) { body += chunk })
+ .on('end', function () {
response = JSON.parse(body);
response.headers = resHeaders;

0 comments on commit eacb351

Please sign in to comment.