Skip to content

Commit

Permalink
correct getter, prefix private variable with underscore
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech committed Dec 4, 2016
1 parent 7d6e24c commit 22446eb
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 35 deletions.
114 changes: 85 additions & 29 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,81 @@ class Hemera extends EventEmitter {

constructor(transport, params) {

super()

this.catalog = Bloomrun()
this.config = Hoek.applyToDefaults(defaultConfig, params || {})
this.transport = transport
this.events = new Kilt([this, this.transport])
this.topics = {}
this.plugins = {}
//Special variables for act and add
this.context$ = {}
this.meta$ = {}
this.plugin$ = {}

this.log = this.config.logger || new DefaultLogger({
level: this.config.logLevel
})
super()

this._config = Hoek.applyToDefaults(defaultConfig, params || {})
this._catalog = Bloomrun()
this._transport = transport
this._events = new Kilt([this, this.transport])
this._topics = {}
this._plugins = {}

//Special variables for act and add
this.context$ = {}
this.meta$ = {}
this.plugin$ = {}

this.log = this._config.logger || new DefaultLogger({
level: this._config.logLevel
})

this.payloadValidator = this._config.payloadValidator || DefaultPayloadValidator

}
/**
*
*
* @readonly
*
* @memberOf Hemera
*/
get plugins() {

return this._plugins;
}
/**
*
*
* @readonly
*
* @memberOf Hemera
*/
get catalog() {

return this._catalog;
}
/**
*
*
* @readonly
*
* @memberOf Hemera
*/
get transport() {

this.payloadValidator = this.config.payloadValidator || DefaultPayloadValidator
return this._transport;
}
/**
*
*
* @readonly
*
* @memberOf Hemera
*/
get topics() {

return this._topics;
}
/**
*
*
* @returns
*
* @memberOf Hemera
*/
get events() {

return this._events;
}
/**
*
Expand All @@ -74,7 +130,7 @@ class Hemera extends EventEmitter {
*/
use(params) {

if (this.plugins[params.attributes.name]) {
if (this._plugins[params.attributes.name]) {
let error = new Errors.HemeraError(Constants.PLUGIN_ALREADY_IN_USE, {
plugin: params.attributes.name
})
Expand All @@ -87,7 +143,7 @@ class Hemera extends EventEmitter {
params.plugin.call(ctx, params.options)

this.log.info(params.attributes.name, Constants.PLUGIN_ADDED)
this.plugins[params.attributes.name] = ctx.plugin$
this._plugins[params.attributes.name] = ctx.plugin$

}
/**
Expand Down Expand Up @@ -193,7 +249,7 @@ class Hemera extends EventEmitter {

//Avoid duplicate subscribers of the emit stream
//We use one subscriber per topic
if (self.topics[topic]) {
if (self._topics[topic]) {
return
}

Expand Down Expand Up @@ -221,7 +277,7 @@ class Hemera extends EventEmitter {
}

let pattern = result.value.pattern
let actMeta = this.catalog.lookup(pattern)
let actMeta = this._catalog.lookup(pattern)

//Check if a handler is registered with this pattern
if (actMeta) {
Expand Down Expand Up @@ -274,7 +330,7 @@ class Hemera extends EventEmitter {
this.send(replyTo, ctx.reply(error), () => {

//let it crash
if (this.config.crashOnFatal) {
if (this._config.crashOnFatal) {

this.fatal()
}
Expand All @@ -298,7 +354,7 @@ class Hemera extends EventEmitter {

})

self.topics[topic] = true
self._topics[topic] = true

}
/**
Expand Down Expand Up @@ -351,7 +407,7 @@ class Hemera extends EventEmitter {
action: cb
}

let handler = this.catalog.lookup(origPattern)
let handler = this._catalog.lookup(origPattern)

//Check if pattern is already registered
if (handler) {
Expand All @@ -364,7 +420,7 @@ class Hemera extends EventEmitter {
}

//Add to bloomrun
this.catalog.add(origPattern, actMeta)
this._catalog.add(origPattern, actMeta)

this.log.info(origPattern, Constants.ADD_ADDED)

Expand Down Expand Up @@ -469,7 +525,7 @@ class Hemera extends EventEmitter {
this.log.fatal(error)

//Let it crash
if (this.config.crashOnFatal) {
if (this._config.crashOnFatal) {

this.fatal()
}
Expand All @@ -493,7 +549,7 @@ class Hemera extends EventEmitter {
handleTimeout(sid, pattern, cb) {

//Handle timeout
this.timeout(sid, pattern.timeout$ || this.config.timeout, 1, () => {
this.timeout(sid, pattern.timeout$ || this._config.timeout, 1, () => {

let error = new Errors.TimeoutError(Constants.ACT_TIMEOUT_ERROR, {
pattern
Expand All @@ -513,7 +569,7 @@ class Hemera extends EventEmitter {
this.log.fatal(error)

//Let it crash
if (this.config.crashOnFatal) {
if (this._config.crashOnFatal) {

this.fatal()
}
Expand Down Expand Up @@ -554,7 +610,7 @@ class Hemera extends EventEmitter {
*/
list(params) {

return this.catalog.list(params)
return this._catalog.list(params)

}
/**
Expand Down
12 changes: 6 additions & 6 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ class Logger {

let self = this

self.config = Hoek.applyToDefaults(defaultConfig, params || {})
self._config = Hoek.applyToDefaults(defaultConfig, params || {})

//Leads to too much listeners in tests
if (this.config.level !== 'silent') {
if (this._config.level !== 'silent') {
Pretty.pipe(process.stdout)
}

this.logger = Pino({
this._logger = Pino({
name: 'app',
safe: true,
level: this.config.level
level: this._config.level
}, Pretty)

//Set levels, create new prototype methods
self.config.levels.forEach((level) => {
self._config.levels.forEach((level) => {

self[level] = function (msg) {

Expand All @@ -72,7 +72,7 @@ class Logger {
*/
log() {

this.logger[arguments[0]].apply(this.logger, Array.prototype.slice.call(arguments).slice(1))
this._logger[arguments[0]].apply(this._logger, Array.prototype.slice.call(arguments).slice(1))
}

}
Expand Down

0 comments on commit 22446eb

Please sign in to comment.