Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Standardize on fn.bind(this). Fixes gh-329

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information...
commit daaab6e8e5855388e093b4e6b521749f317c0e25 1 parent 4883246
Rick Waldron rwaldron authored
Showing with 14 additions and 17 deletions.
  1. +5 −6 cli/lib/plugins/updater.js
  2. +9 −11 cli/tasks/server.js
11 cli/lib/plugins/updater.js
View
@@ -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() {};
@@ -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 {
@@ -261,11 +260,11 @@ updater.getUpdate = function getUpdate( options, cb ) {
} else {
cb( err, update );
}
- });
+ }.bind(this));
} else {
cb();
}
- });
+ }.bind(this));
};
20 cli/tasks/server.js
View
@@ -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
@@ -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) {
@@ -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
@@ -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';
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.