From ab46af5b6bb754f996d1c2dc188a8c4c7fb08aba Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Fri, 13 Dec 2019 09:14:36 +0000 Subject: [PATCH] refactor(deployer): Class syntax --- lib/extend/deployer.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/extend/deployer.js b/lib/extend/deployer.js index c02b8d0fd3..4653662f08 100644 --- a/lib/extend/deployer.js +++ b/lib/extend/deployer.js @@ -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;