Skip to content
This repository
Browse code

Merge pull request #370 from rwldrn/329

Standardize on fn.bind(this). Fixes gh-329
  • Loading branch information...
commit a55ee86c29cfc9ecd01eb776b1b2aab581434809 2 parents 4883246 + daaab6e
Addy Osmani addyosmani authored

Showing 2 changed files with 14 additions and 17 deletions. Show diff stats Hide diff stats

  1. +5 6 cli/lib/plugins/updater.js
  2. +9 11 cli/tasks/server.js
11 cli/lib/plugins/updater.js
@@ -163,7 +163,6 @@ updater.shouldUpdate = function shouldUpdate( update, cb ) {
163 163
164 164 updater.getUpdate = function getUpdate( options, cb ) {
165 165 var localPackage, url;
166   - var self = this;
167 166 var controller = new EventEmitter();
168 167
169 168 cb = cb || function() {};
@@ -243,13 +242,13 @@ updater.getUpdate = function getUpdate( options, cb ) {
243 242 latest: latest,
244 243 date: body.time[ latest ],
245 244 current: options.version,
246   - severity: self.parseUpdateType( options.version, latest )
  245 + severity: this.parseUpdateType( options.version, latest )
247 246 };
248 247
249 248 if ( update.severity !== 'latest' ) {
250   - self.shouldUpdate( update, function( shouldUpdate ) {
  249 + this.shouldUpdate( update, function( shouldUpdate ) {
251 250 if ( shouldUpdate ) {
252   - self.updatePackage( options.name, function( err, data ) {
  251 + this.updatePackage( options.name, function( err, data ) {
253 252 if ( err ) {
254 253 console.error( '\nUpdate error', err );
255 254 } else {
@@ -261,11 +260,11 @@ updater.getUpdate = function getUpdate( options, cb ) {
261 260 } else {
262 261 cb( err, update );
263 262 }
264   - });
  263 + }.bind(this));
265 264 } else {
266 265 cb();
267 266 }
268   - });
  267 + }.bind(this));
269 268 };
270 269
271 270
20 cli/tasks/server.js
@@ -44,8 +44,7 @@ module.exports = function(grunt) {
44 44
45 45 // send a reload command on all stored web socket connection
46 46 Reactor.prototype.reload = function reload(files) {
47   - var self = this,
48   - sockets = this.sockets,
  47 + var sockets = this.sockets,
49 48 changed = files.changed;
50 49
51 50 // go through all sockets, and emit a reload command
@@ -55,8 +54,8 @@ module.exports = function(grunt) {
55 54
56 55 // go throuh all the files that has been marked as changed by grunt
57 56 // and trigger a reload command on each one, for each connection.
58   - changed.forEach(self.reloadFile.bind(self, version));
59   - });
  57 + changed.forEach(this.reloadFile.bind(this, version));
  58 + }, this);
60 59 };
61 60
62 61 Reactor.prototype.reloadFile = function reloadFile(version, filepath) {
@@ -86,7 +85,6 @@ module.exports = function(grunt) {
86 85
87 86 Reactor.prototype.connection = function connection(request, socket, head) {
88 87 var ws = new WebSocket(request, socket, head),
89   - self = this,
90 88 wsId = this.uid = this.uid + 1;
91 89
92 90 // store the new connection
@@ -99,7 +97,7 @@ module.exports = function(grunt) {
99 97 }
100 98
101 99 // parse the JSON data object
102   - var data = self.parseData(event.data);
  100 + var data = this.parseData(event.data);
103 101
104 102 // attach the guessed livereload protocol version to the sokect object
105 103 ws.livereloadVersion = data.command ? '1.7' : '1.6';
@@ -113,23 +111,23 @@ module.exports = function(grunt) {
113 111
114 112 // first handshake
115 113 if ( data.command === 'hello' ) {
116   - return self.hello( data );
  114 + return this.hello( data );
117 115 }
118 116
119 117 // livereload.js emits this
120 118 if ( data.command === 'info' ) {
121   - return self.info( data );
  119 + return this.info( data );
122 120 }
123   - };
  121 + }.bind(this);
124 122
125 123 ws.onclose = function() {
126 124 ws = null;
127   - delete self.sockets[wsId];
  125 + delete this.sockets[wsId];
128 126
129 127 priv.set(this, {
130 128 ws: null
131 129 });
132   - };
  130 + }.bind(this);
133 131
134 132 priv.set(this, {
135 133 ws: ws

0 comments on commit a55ee86

Please sign in to comment.
Something went wrong with that request. Please try again.