mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: collect hook logs in order to reduce console noise, flush on ajaxify loadScript completion
This commit is contained in:
@@ -122,6 +122,7 @@ ajaxify = window.ajaxify || {};
|
|||||||
url: url,
|
url: url,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
hooks.logs.collect();
|
||||||
hooks.fire('action:ajaxify.start', payload);
|
hooks.fire('action:ajaxify.start', payload);
|
||||||
|
|
||||||
ajaxify.count += 1;
|
ajaxify.count += 1;
|
||||||
@@ -304,6 +305,7 @@ ajaxify = window.ajaxify || {};
|
|||||||
}
|
}
|
||||||
ajaxify.loadScript(tpl_url, function done() {
|
ajaxify.loadScript(tpl_url, function done() {
|
||||||
hooks.fire('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });
|
hooks.fire('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });
|
||||||
|
hooks.logs.flush();
|
||||||
});
|
});
|
||||||
ajaxify.widgets.render(tpl_url);
|
ajaxify.widgets.render(tpl_url);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,37 @@ define('hooks', [], () => {
|
|||||||
deprecated: {
|
deprecated: {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
logs: {
|
||||||
|
_collection: new Set(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
Hooks.logs.collect = () => {
|
||||||
|
if (Hooks.logs._collection) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Hooks.logs._collection = new Set();
|
||||||
|
};
|
||||||
|
|
||||||
|
Hooks.logs.log = (...args) => {
|
||||||
|
if (Hooks.logs._collection) {
|
||||||
|
Hooks.logs._collection.add(args);
|
||||||
|
} else {
|
||||||
|
console.log.apply(console, args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Hooks.logs.flush = () => {
|
||||||
|
if (Hooks.logs._collection && Hooks.logs._collection.size) {
|
||||||
|
console.groupCollapsed('[hooks] Changes to hooks on this page …');
|
||||||
|
Hooks.logs._collection.forEach((args) => {
|
||||||
|
console.log.apply(console, args);
|
||||||
|
});
|
||||||
|
console.groupEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete Hooks.logs._collection;
|
||||||
};
|
};
|
||||||
|
|
||||||
Hooks.register = (hookName, method) => {
|
Hooks.register = (hookName, method) => {
|
||||||
@@ -27,7 +58,7 @@ define('hooks', [], () => {
|
|||||||
console.groupEnd();
|
console.groupEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.debug(`[hooks] Registered ${hookName}`, method);
|
Hooks.logs.log(`[hooks] Registered ${hookName}`, method);
|
||||||
};
|
};
|
||||||
Hooks.on = Hooks.register;
|
Hooks.on = Hooks.register;
|
||||||
Hooks.one = (hookName, method) => {
|
Hooks.one = (hookName, method) => {
|
||||||
@@ -51,9 +82,9 @@ define('hooks', [], () => {
|
|||||||
Hooks.unregister = (hookName, method) => {
|
Hooks.unregister = (hookName, method) => {
|
||||||
if (Hooks.loaded[hookName] && Hooks.loaded[hookName].has(method)) {
|
if (Hooks.loaded[hookName] && Hooks.loaded[hookName].has(method)) {
|
||||||
Hooks.loaded[hookName].delete(method);
|
Hooks.loaded[hookName].delete(method);
|
||||||
console.debug(`[hooks] Unregistered ${hookName}`, method);
|
Hooks.logs.log(`[hooks] Unregistered ${hookName}`, method);
|
||||||
} else {
|
} else {
|
||||||
console.debug(`[hooks] Unregistration of ${hookName} failed, passed-in method is not a registered listener or the hook itself has no listeners, currently.`);
|
Hooks.logs.log(`[hooks] Unregistration of ${hookName} failed, passed-in method is not a registered listener or the hook itself has no listeners, currently.`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Hooks.off = Hooks.unregister;
|
Hooks.off = Hooks.unregister;
|
||||||
|
|||||||
Reference in New Issue
Block a user