Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace lodash.debounce with a much smaller, custom debounce function #6550

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"autolinker": "^4.1.0",
"bgutils-js": "^3.1.2",
"electron-context-menu": "^4.0.4",
"lodash.debounce": "^4.0.8",
"marked": "^15.0.5",
"path-browserify": "^1.0.1",
"portal-vue": "^2.1.7",
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/components/ft-list-video/ft-list-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
openExternalLink,
showToast,
toDistractionFreeTitle,
deepCopy
deepCopy,
debounce
} from '../../helpers/utils'
import { deArrowData, deArrowThumbnail } from '../../helpers/sponsorblock'
import debounce from 'lodash.debounce'
import thumbnailPlaceholder from '../../assets/img/thumbnail_placeholder.svg'

export default defineComponent({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineComponent, nextTick } from 'vue'
import { mapActions } from 'vuex'
import debounce from 'lodash.debounce'
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
import FtPrompt from '../ft-prompt/ft-prompt.vue'
import FtButton from '../ft-button/ft-button.vue'
Expand All @@ -9,6 +8,7 @@ import FtInput from '../../components/ft-input/ft-input.vue'
import FtSelect from '../../components/ft-select/ft-select.vue'
import FtToggleSwitch from '../../components/ft-toggle-switch/ft-toggle-switch.vue'
import {
debounce,
showToast,
ctrlFHandler,
getIconForSortPreference
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/general-settings/general-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import FtToggleSwitch from '../ft-toggle-switch/ft-toggle-switch.vue'
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
import FtButton from '../ft-button/ft-button.vue'

import debounce from 'lodash.debounce'
import allLocales from '../../../../static/locales/activeLocales.json'
import { randomArrayItem, showToast } from '../../helpers/utils'
import { debounce, randomArrayItem, showToast } from '../../helpers/utils'
import { translateWindowTitle } from '../../helpers/strings'

export default defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/playlist-info/playlist-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import FtPrompt from '../ft-prompt/ft-prompt.vue'
import FtButton from '../ft-button/ft-button.vue'
import {
ctrlFHandler,
debounce,
formatNumber,
showToast,
getTodayDateStrLocalTimezone,
writeFileWithPicker,
} from '../../helpers/utils'
import debounce from 'lodash.debounce'
import thumbnailPlaceholder from '../../assets/img/thumbnail_placeholder.svg'

export default defineComponent({
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/components/proxy-settings/proxy-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import FtInput from '../ft-input/ft-input.vue'
import FtLoader from '../ft-loader/ft-loader.vue'
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'

import debounce from 'lodash.debounce'

import { IpcChannels } from '../../../constants'
import { showToast } from '../../helpers/utils'
import { debounce, showToast } from '../../helpers/utils'

export default defineComponent({
name: 'ProxySettings',
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ import { mapActions, mapMutations } from 'vuex'
import FtInput from '../ft-input/ft-input.vue'
import FtProfileSelector from '../ft-profile-selector/ft-profile-selector.vue'
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
import debounce from 'lodash.debounce'

import { IpcChannels, KeyboardShortcuts, MIXED_SEARCH_HISTORY_ENTRIES_DISPLAY_LIMIT, MOBILE_WIDTH_THRESHOLD, SEARCH_RESULTS_DISPLAY_LIMIT } from '../../../constants'
import { localizeAndAddKeyboardShortcutToActionTitle, openInternalPath } from '../../helpers/utils'
import { debounce, localizeAndAddKeyboardShortcutToActionTitle, openInternalPath } from '../../helpers/utils'
import { translateWindowTitle } from '../../helpers/strings'
import { clearLocalSearchSuggestionsSession, getLocalSearchSuggestions } from '../../helpers/api/local'
import { getInvidiousSearchSuggestions } from '../../helpers/api/invidious'
Expand Down
24 changes: 24 additions & 0 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,3 +1030,27 @@ export function localizeAndAddKeyboardShortcutToActionTitle(localizedActionTitle
const localizedShortcut = getLocalizedShortcut(unlocalizedShortcut)
return addKeyboardShortcutToActionTitle(localizedActionTitle, localizedShortcut)
}

/**
* @template {Function} T
* @param {T} func
* @param {number} wait
* @returns {T}
*/
export function debounce(func, wait) {
let timeout

// Using a fully fledged function here instead of an arrow function
// so that we can get `this` and pass it onto the original function.
// Vue components using the options API use `this` alot.
return function (...args) {
const context = this

clearTimeout(timeout)

timeout = setTimeout(() => {
timeout = null
func.apply(context, args)
}, wait)
}
}
3 changes: 1 addition & 2 deletions src/renderer/views/History/History.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineComponent } from 'vue'
import { isNavigationFailure, NavigationFailureType } from 'vue-router'
import debounce from 'lodash.debounce'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtCard from '../../components/ft-card/ft-card.vue'
import FtFlexBox from '../../components/ft-flex-box/ft-flex-box.vue'
Expand All @@ -9,7 +8,7 @@ import FtButton from '../../components/ft-button/ft-button.vue'
import FtInput from '../../components/ft-input/ft-input.vue'
import FtAutoLoadNextPageWrapper from '../../components/ft-auto-load-next-page-wrapper/ft-auto-load-next-page-wrapper.vue'
import FtToggleSwitch from '../../components/ft-toggle-switch/ft-toggle-switch.vue'
import { ctrlFHandler } from '../../helpers/utils'
import { ctrlFHandler, debounce } from '../../helpers/utils'

const identity = (v) => v

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/views/Playlist/Playlist.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineComponent, nextTick } from 'vue'
import { mapActions, mapMutations } from 'vuex'
import debounce from 'lodash.debounce'
import FtLoader from '../../components/ft-loader/ft-loader.vue'
import FtCard from '../../components/ft-card/ft-card.vue'
import PlaylistInfo from '../../components/playlist-info/playlist-info.vue'
Expand All @@ -16,6 +15,7 @@ import {
parseLocalPlaylistVideo,
} from '../../helpers/api/local'
import {
debounce,
extractNumberFromString,
getIconForSortPreference,
showToast,
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/views/SubscribedChannels/SubscribedChannels.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ import FtInput from '../../components/ft-input/ft-input.vue'
import FtSubscribeButton from '../../components/FtSubscribeButton/FtSubscribeButton.vue'
import { invidiousGetChannelInfo, youtubeImageUrlToInvidious, invidiousImageUrlToInvidious } from '../../helpers/api/invidious'
import { getLocalChannel, parseLocalChannelHeader } from '../../helpers/api/local'
import { ctrlFHandler } from '../../helpers/utils'
import { ctrlFHandler, debounce } from '../../helpers/utils'
import { useI18n } from '../../composables/use-i18n-polyfill.js'
import store from '../../store/index'
import debounce from 'lodash.debounce'

const route = useRoute()
const router = useRouter()
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/views/UserPlaylists/UserPlaylists.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { defineComponent } from 'vue'
import { mapActions } from 'vuex'
import debounce from 'lodash.debounce'
import FtCard from '../../components/ft-card/ft-card.vue'
import FtFlexBox from '../../components/ft-flex-box/ft-flex-box.vue'
import FtTooltip from '../../components/ft-tooltip/ft-tooltip.vue'
Expand All @@ -12,7 +11,7 @@ import FtInput from '../../components/ft-input/ft-input.vue'
import FtIconButton from '../../components/ft-icon-button/ft-icon-button.vue'
import FtToggleSwitch from '../../components/ft-toggle-switch/ft-toggle-switch.vue'
import FtAutoLoadNextPageWrapper from '../../components/ft-auto-load-next-page-wrapper/ft-auto-load-next-page-wrapper.vue'
import { ctrlFHandler, getIconForSortPreference } from '../../helpers/utils'
import { ctrlFHandler, debounce, getIconForSortPreference } from '../../helpers/utils'
import { isNavigationFailure, NavigationFailureType } from 'vue-router'

const SORT_BY_VALUES = {
Expand Down
Loading