@eroc/core
Advanced tools
Comparing version 0.13.1 to 0.13.5
@@ -1,2 +0,2 @@ | ||
/* @eroc/core v0.13.0 2018-10-30T22:21:33.784Z licensed MIT */ | ||
/* @eroc/core v0.13.5 2018-11-01T13:12:15.385Z licensed MIT */ | ||
var Core = (function (exports) { | ||
@@ -40,4 +40,4 @@ 'use strict'; | ||
} | ||
/** | ||
@@ -50,8 +50,8 @@ * Notifies other modules from an specific notification | ||
notify (notification) { | ||
for(let module in notifications) { | ||
const listening = notifications[module][notification.type]; | ||
if(listening) { | ||
listening.callback.call(listening.context, notification.data); | ||
} | ||
} | ||
Object.values(notifications).forEach(listener => { | ||
const listening = listener[notification.type]; | ||
if (listening) { | ||
listening.callback.call(listening.context, notification.data); | ||
} | ||
}); | ||
} | ||
@@ -66,9 +66,11 @@ | ||
listen(notification) { | ||
if (!Array.isArray(notification)) { | ||
return this.addNotification.apply(this, arguments); | ||
} | ||
const args = Array.from(arguments); | ||
if(!Array.isArray(notification)) return this.addNotification.apply(this, arguments); | ||
for(let i = 0, len = notification.length; i < len; i += 1) { | ||
args[0] = notification[i]; | ||
notification.forEach(aNotification => { | ||
args[0] = aNotification; | ||
this.addNotification.apply(this, args); | ||
} | ||
}); | ||
} | ||
@@ -96,3 +98,3 @@ | ||
if(addNotification) { | ||
if (addNotification) { | ||
notifications[this.module] = notifications[this.module] || {}; | ||
@@ -125,7 +127,7 @@ notifications[this.module][notification] = { | ||
const CoreClass = class { | ||
constructor() { | ||
constructor() { | ||
this.modules = {}; | ||
this.moduleInstances = {}; | ||
} | ||
/** | ||
@@ -139,3 +141,3 @@ * Registers a new module | ||
register (module, constructor, factory = false) { | ||
if(this.modules[module]) { | ||
if (this.modules[module]) { | ||
err('!!module', module); | ||
@@ -159,3 +161,8 @@ return false; | ||
if (!moduleName) { | ||
return this.xAll('start'); | ||
Object.keys(this.modules).forEach(moduleName => { | ||
if (!this.moduleInstances[moduleName]) { | ||
this.start(moduleName); | ||
} | ||
}); | ||
return; | ||
} | ||
@@ -178,3 +185,3 @@ | ||
if(instance.init) { | ||
if (instance.init) { | ||
return instance.init(); | ||
@@ -193,3 +200,6 @@ } | ||
if (!moduleName) { | ||
return this.xAll('stop'); | ||
Object.keys(this.moduleInstances).forEach(alias => { | ||
this.stop(alias); | ||
}); | ||
return; | ||
} | ||
@@ -217,18 +227,5 @@ | ||
/** | ||
* Helper for startAll and stopAll | ||
* | ||
* @method xAll | ||
* @param {string} method the method that will be triggered | ||
*/ | ||
xAll(method) { | ||
for(let module in this.moduleInstances) { | ||
if(this.modules.hasOwnProperty(module)) this[method](module); | ||
} | ||
} | ||
}; | ||
const Core = new CoreClass(); | ||
@@ -235,0 +232,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* @eroc/core v0.13.0 2018-10-30T22:21:33.784Z licensed MIT */ | ||
/* @eroc/core v0.13.5 2018-11-01T13:12:15.385Z licensed MIT */ | ||
/** | ||
@@ -37,4 +37,4 @@ * Handles error messages | ||
} | ||
/** | ||
@@ -47,8 +47,8 @@ * Notifies other modules from an specific notification | ||
notify (notification) { | ||
for(let module in notifications) { | ||
const listening = notifications[module][notification.type]; | ||
if(listening) { | ||
listening.callback.call(listening.context, notification.data); | ||
} | ||
} | ||
Object.values(notifications).forEach(listener => { | ||
const listening = listener[notification.type]; | ||
if (listening) { | ||
listening.callback.call(listening.context, notification.data); | ||
} | ||
}); | ||
} | ||
@@ -63,9 +63,11 @@ | ||
listen(notification) { | ||
if (!Array.isArray(notification)) { | ||
return this.addNotification.apply(this, arguments); | ||
} | ||
const args = Array.from(arguments); | ||
if(!Array.isArray(notification)) return this.addNotification.apply(this, arguments); | ||
for(let i = 0, len = notification.length; i < len; i += 1) { | ||
args[0] = notification[i]; | ||
notification.forEach(aNotification => { | ||
args[0] = aNotification; | ||
this.addNotification.apply(this, args); | ||
} | ||
}); | ||
} | ||
@@ -93,3 +95,3 @@ | ||
if(addNotification) { | ||
if (addNotification) { | ||
notifications[this.module] = notifications[this.module] || {}; | ||
@@ -122,7 +124,7 @@ notifications[this.module][notification] = { | ||
const CoreClass = class { | ||
constructor() { | ||
constructor() { | ||
this.modules = {}; | ||
this.moduleInstances = {}; | ||
} | ||
/** | ||
@@ -136,3 +138,3 @@ * Registers a new module | ||
register (module, constructor, factory = false) { | ||
if(this.modules[module]) { | ||
if (this.modules[module]) { | ||
err('!!module', module); | ||
@@ -156,3 +158,8 @@ return false; | ||
if (!moduleName) { | ||
return this.xAll('start'); | ||
Object.keys(this.modules).forEach(moduleName => { | ||
if (!this.moduleInstances[moduleName]) { | ||
this.start(moduleName); | ||
} | ||
}); | ||
return; | ||
} | ||
@@ -175,3 +182,3 @@ | ||
if(instance.init) { | ||
if (instance.init) { | ||
return instance.init(); | ||
@@ -190,3 +197,6 @@ } | ||
if (!moduleName) { | ||
return this.xAll('stop'); | ||
Object.keys(this.moduleInstances).forEach(alias => { | ||
this.stop(alias); | ||
}); | ||
return; | ||
} | ||
@@ -214,20 +224,7 @@ | ||
/** | ||
* Helper for startAll and stopAll | ||
* | ||
* @method xAll | ||
* @param {string} method the method that will be triggered | ||
*/ | ||
xAll(method) { | ||
for(let module in this.moduleInstances) { | ||
if(this.modules.hasOwnProperty(module)) this[method](module); | ||
} | ||
} | ||
}; | ||
const Core = new CoreClass(); | ||
export { Core, CoreClass }; |
@@ -1,2 +0,2 @@ | ||
/* @eroc/core v0.13.0 2018-10-30T22:21:33.784Z licensed MIT */ | ||
/* @eroc/core v0.13.5 2018-11-01T13:12:15.385Z licensed MIT */ | ||
(function (global, factory) { | ||
@@ -43,4 +43,4 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
} | ||
/** | ||
@@ -53,8 +53,8 @@ * Notifies other modules from an specific notification | ||
notify (notification) { | ||
for(let module in notifications) { | ||
const listening = notifications[module][notification.type]; | ||
if(listening) { | ||
listening.callback.call(listening.context, notification.data); | ||
} | ||
} | ||
Object.values(notifications).forEach(listener => { | ||
const listening = listener[notification.type]; | ||
if (listening) { | ||
listening.callback.call(listening.context, notification.data); | ||
} | ||
}); | ||
} | ||
@@ -69,9 +69,11 @@ | ||
listen(notification) { | ||
if (!Array.isArray(notification)) { | ||
return this.addNotification.apply(this, arguments); | ||
} | ||
const args = Array.from(arguments); | ||
if(!Array.isArray(notification)) return this.addNotification.apply(this, arguments); | ||
for(let i = 0, len = notification.length; i < len; i += 1) { | ||
args[0] = notification[i]; | ||
notification.forEach(aNotification => { | ||
args[0] = aNotification; | ||
this.addNotification.apply(this, args); | ||
} | ||
}); | ||
} | ||
@@ -99,3 +101,3 @@ | ||
if(addNotification) { | ||
if (addNotification) { | ||
notifications[this.module] = notifications[this.module] || {}; | ||
@@ -128,7 +130,7 @@ notifications[this.module][notification] = { | ||
const CoreClass = class { | ||
constructor() { | ||
constructor() { | ||
this.modules = {}; | ||
this.moduleInstances = {}; | ||
} | ||
/** | ||
@@ -142,3 +144,3 @@ * Registers a new module | ||
register (module, constructor, factory = false) { | ||
if(this.modules[module]) { | ||
if (this.modules[module]) { | ||
err('!!module', module); | ||
@@ -162,3 +164,8 @@ return false; | ||
if (!moduleName) { | ||
return this.xAll('start'); | ||
Object.keys(this.modules).forEach(moduleName => { | ||
if (!this.moduleInstances[moduleName]) { | ||
this.start(moduleName); | ||
} | ||
}); | ||
return; | ||
} | ||
@@ -181,3 +188,3 @@ | ||
if(instance.init) { | ||
if (instance.init) { | ||
return instance.init(); | ||
@@ -196,3 +203,6 @@ } | ||
if (!moduleName) { | ||
return this.xAll('stop'); | ||
Object.keys(this.moduleInstances).forEach(alias => { | ||
this.stop(alias); | ||
}); | ||
return; | ||
} | ||
@@ -220,18 +230,5 @@ | ||
/** | ||
* Helper for startAll and stopAll | ||
* | ||
* @method xAll | ||
* @param {string} method the method that will be triggered | ||
*/ | ||
xAll(method) { | ||
for(let module in this.moduleInstances) { | ||
if(this.modules.hasOwnProperty(module)) this[method](module); | ||
} | ||
} | ||
}; | ||
const Core = new CoreClass(); | ||
@@ -238,0 +235,0 @@ |
{ | ||
"name": "@eroc/core", | ||
"version": "0.13.1", | ||
"version": "0.13.5", | ||
"description": "Lightweight framework for scalable applications", | ||
@@ -5,0 +5,0 @@ "author": "Mauricio Soares", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28651
577