hubs
Version:
``` Caryl ------ courier3 / \ / \ courier1 courier2
50 lines (40 loc) • 995 B
JavaScript
const Courier = require('./courier')
const protocol = require('./protocol')
const defaultProtocols = require('./defaultProtocols')
/**
* Courier Hubs
*
* @class Hubs
*/
class Hubs{
constructor(){
this.globelPlugin = []
this.protocol = protocol
this._registerDefaultProtocol()
}
createCourier(reqItems){
var courier = new Courier(reqItems, this.protocol)
this._applyAllPlugin(courier)
return courier
}
_applyAllPlugin(courier){
this.globelPlugin.forEach(plugin=>courier.applyPlugin(plugin))
}
/**
* apply plugin that affect all courier
*
* @param {any} plugin
*
* @memberof Caryl
*/
applyPlugin(plugin){
this.globelPlugin.push(plugin)
}
registerProtocol(config){
this.protocol.registerRequestor(config)
}
_registerDefaultProtocol(){
defaultProtocols.forEach(p=>this.registerProtocol(p))
}
}
module.exports = Hubs