add debug switch for console outputs in JS utilRegistry
This commit is contained in:
parent
2c04f6f670
commit
c32fee8a9b
@ -4,6 +4,8 @@
|
|||||||
var registeredUtils = [];
|
var registeredUtils = [];
|
||||||
var activeUtilInstances = [];
|
var activeUtilInstances = [];
|
||||||
|
|
||||||
|
var DEBUG_MODE = 2;
|
||||||
|
|
||||||
// Registry
|
// Registry
|
||||||
// (revealing module pattern)
|
// (revealing module pattern)
|
||||||
window.UtilRegistry = (function() {
|
window.UtilRegistry = (function() {
|
||||||
@ -24,7 +26,13 @@
|
|||||||
* @param util Object Utility that should be added to the registry
|
* @param util Object Utility that should be added to the registry
|
||||||
*/
|
*/
|
||||||
function registerUtil(util) {
|
function registerUtil(util) {
|
||||||
console.log('registering util', util);
|
if (DEBUG_MODE > 0) {
|
||||||
|
console.log('registering util "' + util.name + '"');
|
||||||
|
}
|
||||||
|
if (DEBUG_MODE > 2) {
|
||||||
|
console.log({ util });
|
||||||
|
}
|
||||||
|
|
||||||
registeredUtils.push(util);
|
registeredUtils.push(util);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,14 +49,16 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupAllUtils() {
|
function setupAllUtils() {
|
||||||
console.log('setting up all registered utils');
|
|
||||||
registeredUtils.forEach(function(util) {
|
registeredUtils.forEach(function(util) {
|
||||||
setupUtil(util);
|
setupUtil(util);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupUtil(util, scope) {
|
function setupUtil(util, scope) {
|
||||||
console.log('setting up util', { util });
|
if (DEBUG_MODE > 2) {
|
||||||
|
console.log('setting up util', { util });
|
||||||
|
}
|
||||||
|
|
||||||
scope = scope || document;
|
scope = scope || document;
|
||||||
|
|
||||||
if (util && typeof util.setup === 'function') {
|
if (util && typeof util.setup === 'function') {
|
||||||
@ -60,7 +70,9 @@
|
|||||||
try {
|
try {
|
||||||
utilInstance = util.setup(element);
|
utilInstance = util.setup(element);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
console.warn('Error while trying to initialize a utility!', { util , element, err });
|
if (DEBUG_MODE > 0) {
|
||||||
|
console.warn('Error while trying to initialize a utility!', { util , element, err });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (utilInstance) {
|
if (utilInstance) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user