Skip to content

Commit

Permalink
modularize the class binding
Browse files Browse the repository at this point in the history
one less TODO \o/
  • Loading branch information
sindresorhus committed Aug 9, 2016
1 parent adc823e commit 40b4bcd
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 20 deletions.
5 changes: 2 additions & 3 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var findCacheDir = require('find-cache-dir');
var debounce = require('lodash.debounce');
var ms = require('ms');
var AvaFiles = require('ava-files');
var autoBind = require('auto-bind');
var AvaError = require('./lib/ava-error');
var fork = require('./lib/fork');
var CachingPrecompiler = require('./lib/caching-precompiler');
Expand Down Expand Up @@ -38,9 +39,7 @@ function Api(options) {
return ret;
});

Object.keys(Api.prototype).forEach(function (key) {
this[key] = this[key].bind(this);
}, this);
autoBind(this);
}

util.inherits(Api, EventEmitter);
Expand Down
5 changes: 2 additions & 3 deletions lib/caching-precompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var cachingTransform = require('caching-transform');
var stripBom = require('strip-bom');
var md5Hex = require('md5-hex');
var packageHash = require('package-hash');
var autoBind = require('auto-bind');
var babelConfigHelper = require('./babel-config');

function CachingPrecompiler(cacheDirPath, babelConfig) {
Expand All @@ -17,9 +18,7 @@ function CachingPrecompiler(cacheDirPath, babelConfig) {
this.cacheDirPath = cacheDirPath;
this.fileHashes = {};

Object.keys(CachingPrecompiler.prototype).forEach(function (name) {
this[name] = this[name].bind(this);
}, this);
autoBind(this);

this.transform = this._createTransform();
}
Expand Down
5 changes: 2 additions & 3 deletions lib/concurrent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var Promise = require('bluebird');
var isPromise = require('is-promise');
var autoBind = require('auto-bind');
var AvaError = require('./ava-error');

function noop() {}
Expand All @@ -22,9 +23,7 @@ function Concurrent(tests, bail) {
this.tests = tests;
this.bail = bail || false;

Object.keys(Concurrent.prototype).forEach(function (key) {
this[key] = this[key].bind(this);
}, this);
autoBind(this);
}

Concurrent.prototype.run = function () {
Expand Down
7 changes: 3 additions & 4 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
'use strict';
var autoBind = require('auto-bind');

function Logger(reporter) {
if (!(this instanceof Logger)) {
throw new TypeError('Class constructor Logger cannot be invoked without \'new\'');
}

Object.keys(Logger.prototype).forEach(function (key) {
this[key] = this[key].bind(this);
}, this);

this.reporter = reporter;

autoBind(this);
}

module.exports = Logger;
Expand Down
5 changes: 2 additions & 3 deletions lib/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var chalk = require('chalk');
var isObj = require('is-obj');
var flatten = require('arr-flatten');
var figures = require('figures');
var autoBind = require('auto-bind');
var prefixTitle = require('./prefix-title');

function RunStatus(opts) {
Expand Down Expand Up @@ -33,9 +34,7 @@ function RunStatus(opts) {
this.stats = [];
this.tests = [];

Object.keys(RunStatus.prototype).forEach(function (key) {
this[key] = this[key].bind(this);
}, this);
autoBind(this);
}

util.inherits(RunStatus, EventEmitter);
Expand Down
6 changes: 2 additions & 4 deletions lib/sequence.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
var isPromise = require('is-promise');
var autoBind = require('auto-bind');
var AvaError = require('./ava-error');

function noop() {}
Expand All @@ -21,10 +22,7 @@ function Sequence(tests, bail) {
this.tests = tests;
this.bail = bail || false;

// TODO(vdemedes): separate into a utility (it's being used in serveral places)
Object.keys(Sequence.prototype).forEach(function (key) {
this[key] = this[key].bind(this);
}, this);
autoBind(this);
}

Sequence.prototype.run = function () {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"array-union": "^1.0.1",
"array-uniq": "^1.0.2",
"arrify": "^1.0.0",
"auto-bind": "^0.1.0",
"ava-files": "^0.1.1",
"ava-init": "^0.1.0",
"babel-code-frame": "^6.7.5",
Expand Down

0 comments on commit 40b4bcd

Please sign in to comment.