Skip to content

Commit

Permalink
fix: checkSession debounce function
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Jun 29, 2024
1 parent 2a31537 commit 6229d80
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,34 +458,24 @@ Actions.init([
}
]);

// Debounce function
function debounce(func, wait) {
let timeout;
return function (...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}

// Function to send socket request
function sendCheckSession() {
Crud.socket.send({
method: 'checkSession',
broadcast: false,
broadcastBrowser: false
});
let checkSessionTimeout
function checkSession() {
clearTimeout(checkSessionTimeout);
checkSessionTimeout = setTimeout(function () {
Crud.socket.send({
method: 'checkSession',
broadcast: false,
broadcastBrowser: false
});
}, 500);
}

// Create a debounced version of the sendCheckSession function
const debouncedSendCheckSession = debounce(sendCheckSession, 500); // Adjust the delay (in milliseconds) as needed

// Initialize the observer
Observer.init({
name: 'CoCreateUserSessionAddedNodes',
observe: ['addedNodes'],
target: '[session]',
callback: () => {
debouncedSendCheckSession();
checkSession();
}
});

Expand Down

0 comments on commit 6229d80

Please sign in to comment.