Skip to content

Commit

Permalink
Merge pull request #370 from rwldrn/329
Browse files Browse the repository at this point in the history
Standardize on fn.bind(this). Fixes gh-329
  • Loading branch information
addyosmani committed Sep 11, 2012
2 parents 4883246 + daaab6e commit a55ee86
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
11 changes: 5 additions & 6 deletions cli/lib/plugins/updater.js
Expand Up @@ -163,7 +163,6 @@ updater.shouldUpdate = function shouldUpdate( update, cb ) {

updater.getUpdate = function getUpdate( options, cb ) {
var localPackage, url;
var self = this;
var controller = new EventEmitter();

cb = cb || function() {};
Expand Down Expand Up @@ -243,13 +242,13 @@ updater.getUpdate = function getUpdate( options, cb ) {
latest: latest,
date: body.time[ latest ],
current: options.version,
severity: self.parseUpdateType( options.version, latest )
severity: this.parseUpdateType( options.version, latest )
};

if ( update.severity !== 'latest' ) {
self.shouldUpdate( update, function( shouldUpdate ) {
this.shouldUpdate( update, function( shouldUpdate ) {
if ( shouldUpdate ) {
self.updatePackage( options.name, function( err, data ) {
this.updatePackage( options.name, function( err, data ) {
if ( err ) {
console.error( '\nUpdate error', err );
} else {
Expand All @@ -261,11 +260,11 @@ updater.getUpdate = function getUpdate( options, cb ) {
} else {
cb( err, update );
}
});
}.bind(this));
} else {
cb();
}
});
}.bind(this));
};


Expand Down
20 changes: 9 additions & 11 deletions cli/tasks/server.js
Expand Up @@ -44,8 +44,7 @@ module.exports = function(grunt) {

// send a reload command on all stored web socket connection
Reactor.prototype.reload = function reload(files) {
var self = this,
sockets = this.sockets,
var sockets = this.sockets,
changed = files.changed;

// go through all sockets, and emit a reload command
Expand All @@ -55,8 +54,8 @@ module.exports = function(grunt) {

// go throuh all the files that has been marked as changed by grunt
// and trigger a reload command on each one, for each connection.
changed.forEach(self.reloadFile.bind(self, version));
});
changed.forEach(this.reloadFile.bind(this, version));
}, this);
};

Reactor.prototype.reloadFile = function reloadFile(version, filepath) {
Expand Down Expand Up @@ -86,7 +85,6 @@ module.exports = function(grunt) {

Reactor.prototype.connection = function connection(request, socket, head) {
var ws = new WebSocket(request, socket, head),
self = this,
wsId = this.uid = this.uid + 1;

// store the new connection
Expand All @@ -99,7 +97,7 @@ module.exports = function(grunt) {
}

// parse the JSON data object
var data = self.parseData(event.data);
var data = this.parseData(event.data);

// attach the guessed livereload protocol version to the sokect object
ws.livereloadVersion = data.command ? '1.7' : '1.6';
Expand All @@ -113,23 +111,23 @@ module.exports = function(grunt) {

// first handshake
if ( data.command === 'hello' ) {
return self.hello( data );
return this.hello( data );
}

// livereload.js emits this
if ( data.command === 'info' ) {
return self.info( data );
return this.info( data );
}
};
}.bind(this);

ws.onclose = function() {
ws = null;
delete self.sockets[wsId];
delete this.sockets[wsId];

priv.set(this, {
ws: null
});
};
}.bind(this);

priv.set(this, {
ws: ws
Expand Down

0 comments on commit a55ee86

Please sign in to comment.