Skip to content

Commit 6229d80

Browse files
committed
fix: checkSession debounce function
1 parent 2a31537 commit 6229d80

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/client.js

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -458,34 +458,24 @@ Actions.init([
458458
}
459459
]);
460460

461-
// Debounce function
462-
function debounce(func, wait) {
463-
let timeout;
464-
return function (...args) {
465-
clearTimeout(timeout);
466-
timeout = setTimeout(() => func.apply(this, args), wait);
467-
};
468-
}
469-
470-
// Function to send socket request
471-
function sendCheckSession() {
472-
Crud.socket.send({
473-
method: 'checkSession',
474-
broadcast: false,
475-
broadcastBrowser: false
476-
});
461+
let checkSessionTimeout
462+
function checkSession() {
463+
clearTimeout(checkSessionTimeout);
464+
checkSessionTimeout = setTimeout(function () {
465+
Crud.socket.send({
466+
method: 'checkSession',
467+
broadcast: false,
468+
broadcastBrowser: false
469+
});
470+
}, 500);
477471
}
478472

479-
// Create a debounced version of the sendCheckSession function
480-
const debouncedSendCheckSession = debounce(sendCheckSession, 500); // Adjust the delay (in milliseconds) as needed
481-
482-
// Initialize the observer
483473
Observer.init({
484474
name: 'CoCreateUserSessionAddedNodes',
485475
observe: ['addedNodes'],
486476
target: '[session]',
487477
callback: () => {
488-
debouncedSendCheckSession();
478+
checkSession();
489479
}
490480
});
491481

0 commit comments

Comments
 (0)