mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-20 07:31:07 -05:00
Refactor cleanup logic in search script for improved readability and maintainability
This commit is contained in:
@@ -52,28 +52,7 @@ document.addEventListener('alpine:init', () => {
|
|||||||
const savedFilters = localStorage.getItem('rideFilters');
|
const savedFilters = localStorage.getItem('rideFilters');
|
||||||
|
|
||||||
// Set up destruction handler
|
// Set up destruction handler
|
||||||
this.$cleanup = () => {
|
this.$cleanup = this.performCleanup.bind(this);
|
||||||
// Remove all bound event listeners
|
|
||||||
this.boundHandlers.forEach((handler, event) => {
|
|
||||||
if (event === 'popstate') {
|
|
||||||
window.removeEventListener(event, handler);
|
|
||||||
} else {
|
|
||||||
document.body.removeEventListener(event, handler);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.boundHandlers.clear();
|
|
||||||
|
|
||||||
// Cancel any pending requests
|
|
||||||
if (this.currentRequest) {
|
|
||||||
this.currentRequest.abort();
|
|
||||||
this.currentRequest = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear any pending timeouts
|
|
||||||
if (this.suggestionTimeout) {
|
|
||||||
clearTimeout(this.suggestionTimeout);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
if (savedFilters) {
|
if (savedFilters) {
|
||||||
const filters = JSON.parse(savedFilters);
|
const filters = JSON.parse(savedFilters);
|
||||||
Object.entries(filters).forEach(([key, value]) => {
|
Object.entries(filters).forEach(([key, value]) => {
|
||||||
@@ -316,10 +295,35 @@ document.addEventListener('alpine:init', () => {
|
|||||||
bottom: 1rem;
|
bottom: 1rem;
|
||||||
right: 1rem;
|
right: 1rem;
|
||||||
z-index: 50;
|
z-index: 50;
|
||||||
padding: 0.5rem 1rem;
|
},
|
||||||
background: rgba(37, 99, 235, 0.95);
|
|
||||||
border-radius: 0.5rem;
|
performCleanup() {
|
||||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
// Remove all bound event listeners
|
||||||
|
this.boundHandlers.forEach(this.removeEventHandler.bind(this));
|
||||||
|
this.boundHandlers.clear();
|
||||||
|
|
||||||
|
// Cancel any pending requests
|
||||||
|
if (this.currentRequest) {
|
||||||
|
this.currentRequest.abort();
|
||||||
|
this.currentRequest = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear any pending timeouts
|
||||||
|
if (this.suggestionTimeout) {
|
||||||
|
clearTimeout(this.suggestionTimeout);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
removeEventHandler(handler, event) {
|
||||||
|
if (event === 'popstate') {
|
||||||
|
window.removeEventListener(event, handler);
|
||||||
|
} else {
|
||||||
|
document.body.removeEventListener(event, handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
</script>
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 0.5rem;
|
gap: 0.5rem;
|
||||||
|
|||||||
Reference in New Issue
Block a user