Skip to content

Commit

Permalink
Merge pull request #3945 from curbengh/deployer-class
Browse files Browse the repository at this point in the history
refactor(deployer): Class syntax
  • Loading branch information
curbengh authored Dec 19, 2019
2 parents 4c86aac + ab46af5 commit 91e5c32
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions lib/extend/deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@

const Promise = require('bluebird');

function Deployer() {
this.store = {};
}
class Deployer {
constructor() {
this.store = {};
}

Deployer.prototype.list = function() {
return this.store;
};
list() {
return this.store;
}

Deployer.prototype.get = function(name) {
return this.store[name];
};
get(name) {
return this.store[name];
}

Deployer.prototype.register = function(name, fn) {
if (!name) throw new TypeError('name is required');
if (typeof fn !== 'function') throw new TypeError('fn must be a function');
register(name, fn) {
if (!name) throw new TypeError('name is required');
if (typeof fn !== 'function') throw new TypeError('fn must be a function');

if (fn.length > 1) {
fn = Promise.promisify(fn);
} else {
fn = Promise.method(fn);
}
if (fn.length > 1) {
fn = Promise.promisify(fn);
} else {
fn = Promise.method(fn);
}

this.store[name] = fn;
};
this.store[name] = fn;
}
}

module.exports = Deployer;

0 comments on commit 91e5c32

Please sign in to comment.