Informal code review to tidy up logger buffer fetching implementation

This commit is contained in:
Raymond Hill 2018-12-23 15:35:32 -05:00
parent ddee2bff13
commit 99cdec5ba6
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 46 additions and 39 deletions

View File

@ -505,10 +505,7 @@ var truncateLog = function(size) {
/******************************************************************************/
const onLogBufferRead = function(response) {
if ( !response || response.unavailable ) {
readLogBufferAsync();
return;
}
if ( !response || response.unavailable ) { return; }
// Disable tooltips?
if (
@ -565,45 +562,57 @@ const onLogBufferRead = function(response) {
'disabled',
tbody.querySelector('tr') === null
);
readLogBufferAsync();
};
/******************************************************************************/
// This can be called only once, at init time. After that, this will be called
// automatically. If called after init time, this will be messy, and this would
// require a bit more code to ensure no multi time out events.
const readLogBuffer = (function() {
let timer;
const readLogBuffer = function() {
if ( logger.ownerId === undefined ) { return; }
const msg = {
what: 'readAll',
ownerId: logger.ownerId,
tabIdsToken: allTabIdsToken,
const readLogBufferNow = function() {
if ( logger.ownerId === undefined ) { return; }
const msg = {
what: 'readAll',
ownerId: logger.ownerId,
tabIdsToken: allTabIdsToken,
};
// This is to detect changes in the position or size of the logger
// popup window (if in use).
if (
popupLoggerBox instanceof Object &&
(
self.screenX !== popupLoggerBox.x ||
self.screenY !== popupLoggerBox.y ||
self.outerWidth !== popupLoggerBox.w ||
self.outerHeight !== popupLoggerBox.h
)
) {
popupLoggerBox.x = self.screenX;
popupLoggerBox.y = self.screenY;
popupLoggerBox.w = self.outerWidth;
popupLoggerBox.h = self.outerHeight;
msg.popupLoggerBoxChanged = true;
}
vAPI.messaging.send('loggerUI', msg, response => {
timer = undefined;
onLogBufferRead(response);
readLogBufferLater();
});
};
if (
popupLoggerBox instanceof Object &&
(
self.screenX !== popupLoggerBox.x ||
self.screenY !== popupLoggerBox.y ||
self.outerWidth !== popupLoggerBox.w ||
self.outerHeight !== popupLoggerBox.h
)
) {
popupLoggerBox.x = self.screenX;
popupLoggerBox.y = self.screenY;
popupLoggerBox.w = self.outerWidth;
popupLoggerBox.h = self.outerHeight;
msg.popupLoggerBoxChanged = true;
}
vAPI.messaging.send('loggerUI', msg, onLogBufferRead);
};
const readLogBufferAsync = function() {
if ( logger.ownerId === undefined ) { return; }
vAPI.setTimeout(readLogBuffer, 1200);
};
const readLogBufferLater = function() {
if ( timer !== undefined ) { return; }
if ( logger.ownerId === undefined ) { return; }
timer = vAPI.setTimeout(readLogBufferNow, 1200);
};
readLogBufferNow();
return readLogBufferLater;
})();
/******************************************************************************/
@ -1802,7 +1811,7 @@ const grabView = function() {
if ( logger.ownerId === undefined ) {
logger.ownerId = Date.now();
}
readLogBufferAsync();
readLogBuffer();
};
const releaseView = function() {
@ -1821,8 +1830,6 @@ window.addEventListener('beforeunload', releaseView);
/******************************************************************************/
readLogBuffer();
uDom('#pageSelector').on('change', pageSelectorChanged);
uDom('#refresh').on('click', reloadTab);