Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(deployer): Class syntax #3945

Merged
merged 1 commit into from
Dec 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;