Skip to content

Commit

Permalink
refactor(deployer): Class syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Dec 13, 2019
1 parent e4a5292 commit ab46af5
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 ab46af5

Please sign in to comment.